2

I am including a jQuery file like this:

<script type="text/javascript" src="jquery-1.8.0.min.js"></script>

I am having a code like this:

if($.isNumeric(now))
{            
  alert("yes");
}
else
{
  alert("no");
}

But when I run this script get an error:

$.isNumeric is not a function

What do I need to do?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Naveen K
  • 859
  • 4
  • 14
  • 29
  • 1
    Try using `jQuery.isNumeric(row)`. If that works, do [this](http://stackoverflow.com/a/6109983/1144176). It is also possible that there is a conflict if you are using other JS libraries. – Jake Stoeffler Oct 20 '12 at 06:47

2 Answers2

2

Wrap your code in $(document).ready(function () { //your code goes here... }); Please refer to jQuery.ready() for more details.

Alternatively, you can simply place your code before the </body>.

Also, you might want to try to replace $ with jQuery and see if there'd be any conflicts in you javascript, e.g. jQuery.isNumeric("-10");

If it does turn out to be conflicts, you can add this line of code, jQuery.noConflict(); at the beginning of your jQuery code. Please refer to jQuery.noConflict() for more details.

Check this post on Stackoverflow which might also be helpful to you.

Community
  • 1
  • 1
woodykiddy
  • 6,074
  • 16
  • 59
  • 100
0

First, make sure the JQuery script has loaded by using document.ready (or just make sure your script comes after the JQuery script tag).

$(document).ready(function() {
    var now = 1;
    alert($.isNumeric(now) ? "yes" : "no");
});

Second, make sure the JQuery source actually loaded correctly... maybe try the JQuery CDN.

<script src='http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.2.min.js'></script>
McGarnagle
  • 101,349
  • 31
  • 229
  • 260