Im having a problem using an isNumeric jQuery function to check if a variable is a number.
I am getting an error
Uncaught TypeError: Object function (a,b){return new e.fn.init(a,b,h)} has no method 'isNumeric'
Here is my code
var scroll = 4;
$.isNumeric(scroll);
if (false) {
scroll = 0;
tabChange(menuTab, page, scroll);
} else {
tabChange(menuTab, page, scroll);
}
I thought this may be caused by having my code being run before jQuery has loaded but this is not the case.
Also the jQuery documentation is very unclear to me.
Which version of jQuery are you using? .isNumeric() was added in 1.7, and if you're using an earlier version it's not available, which would give that error.
Another possibility is that you have Prototype or some other JS library running as well - try using jQuery.isNumeric(scroll); instead of the $ notation.
Related
I'm using jQuery with an Electron app, but I always get an error that seems to be corresponding with jQuery's tween function.
I'm loading jQuery via standard node require:
<script type="text/javascript">window.$ = window.jQuery = require('jquery');</script>
When I include jQuery via a script src, I get the same error (jQuery version 3.3.1)
for example calling $("#loading-overlay").fadeOut(200); causes:
Uncaught TypeError: (Animation.tweeners[prop] || []).concat is not a function
at createTween ([PATH]/node_modules/jquery/dist/jquery.js:6848)
at Object.defaultPrefilter ([PATH]/node_modules/jquery/dist/jquery.js:7021)
at Animation ([PATH]/node_modules/jquery/dist/jquery.js:7160)
at HTMLDivElement.doAnimation ([PATH]/node_modules/jquery/dist/jquery.js:7293)
at Function.dequeue ([PATH]/node_modules/jquery/dist/jquery.js:4376)
at HTMLDivElement.<anonymous> ([PATH]/node_modules/jquery/dist/jquery.js:4418)
at Function.each ([PATH]/node_modules/jquery/dist/jquery.js:354)
at jQuery.fn.init.each ([PATH]/node_modules/jquery/dist/jquery.js:189)
at jQuery.fn.init.queue ([PATH]/node_modules/jquery/dist/jquery.js:4411)
at jQuery.fn.init.animate ([PATH]/node_modules/jquery/dist/jquery.js:7304)
I'm only having this problem with Electron (version 4.0). Does anyone know what this is caused by?
OK, this was stupidity on my part. Autocomplete made me add the method "each" to the Object prototype instead of my custom class... This apparently confused jQuery because it found the property "each" in Animation.tweeners (because it was in all Objects).
But I learned, when facing a really confusing error that makes no sense, check if you accidentally overwrote a prototype you didn't want to change...
I have tried multiple combination of usage of code to make the Prototype and jQuery to work, but no luck yet.
Here is what I have currently.
index.html:
<script src="https://ajax.googleapis.com/ajax/libs/prototype/1.7.2.0/prototype.js"></script>
<script src="http://code.jquery.com/jquery.js"></script>
<script src="MAIN_JS_FILE.js"></script>`
main_js_file.js:
jQuery(document).ready(function() {
var jsq = [];
jsq.push(AJAX_CALL_FOR_FETCHING_JS_FILE_1);
jsq.push(AJAX_CALL_FOR_FETCHING_JS_FILE_2);
jsq.push(AJAX_CALL_FOR_FETCHING_JS_FILE_3);
var deferredjs = jQuery.when.apply(jQuery, jsq);
deferredjs.done(function() {
//Various variable initialization
//Various function definition.
}
});
Now when page is loaded (page loads properly), chrome console shows an error message:
Uncaught TypeError: undefined is not a function.
When clicked on the error file link, it points to element.dispatchEvent(event); in the prototype.js file, line no 7066.
Any help is appreciated.
Thanks.
Edit: I have changed the MAIN_JS_FILE.js file to use only jQuery instead of $
So now there is not a single javascript code that uses $ and still the undefined error is displayed.
If I now use jQuery.noConflict(); before .ready() function, then the $.when.apply code does not even execute.
As #steven iseki mentioned in comment you, can use jQuery.noConflict. You can read on their website that:
Many JavaScript libraries use $ as a function or variable name, just as jQuery does. In jQuery's case, $ is just an alias for jQuery, so all functionality is available without using $.
And it's indeed a case with Prototype also using $ sign.
Also, remember to use jQuery instead of $ sign in your jQuery code, e.g.:
jQuery(selector).on('click', function(){...});
I don't think there's jQuery Conflict error here. Try changing your code from main.js. Try alternate method to get your task done here. I analyzed your code but prototype.js has a way of hiding real thing.
I have problem with website slide. after clicking on inspect element in chrome i get massage
"Uncaught TypeError: undefined is not a function" in file custom.js
here is file code
jQuery(document).ready(function() {
jQuery('#slider').nivoSlider({pauseTime: 4500}); });
}
here is website address http://myisraeltoday.com using WordPress
Theme: http://wordpress.org/themes/effect
Help needed
That means that you're calling something as a function (or method), when in fact it doesn't exist. You're calling three functions:
jQuery
jQuery(document).ready
jQuery('#slider').nivoSlider
The third of these is most likely the problem.
try changing your code to this :
$(document).ready(function() {
$('#slider').nivoSlider({'pauseTime': 4500});
});
PS : Note the }); at the end not just the $
I want to iterate over all the forms present in a div. So I am using the following code for this
$('#divid form').each(function (index, formDetails) {
if (formDetails) {
console.log($(formDetails).attr('id'));
}
});
This is working fine in Mozilla with no issues but when I run this code in Chrome sometimes it throws the following error.
This error is coming
Uncaught TypeError: Cannot read property 'Constructor' of undefined
I am using Version 33.0.1750.117 m of Chrome.
Why this error is coming I am not able to understand?
Sounds like you don't have jQuery included before your try and load your functions.
Wrap your javascript code inside the below function:
$(document).ready(function() {
alert('loaded');
}
Also check if the initial is $ or jQuery
using the Firebug console I'm trying to test whether this code is working:
$(window).bind("load", function() {
$('#tab1link').click(function() {
$('#tab2').hide();
$('#tab2').removeClass('selected');
$('#tab1').show();
$('#tab1').addClass('selected');
});
$('#tab2link').click(function() {
$('#tab1').hide();
$('#tab1').removeClass('selected');
$('#tab2').show();
$('#tab2').addClass('selected');
});
});
but this:
console.log($('#tab2').hasClass('selected'))
returns the error:
TypeError: $("#tab2").hasClass is not a function { message="$("#tab2").hasClass is not a function", more...}
Does anyone know why the above console command is incorrect? (Not a jQuery expert...)
Based on the link below, I think it should work...
http://api.jquery.com/hasClass/
Thanks!
Try refreshing the console/page because sometimes it doesn't properly assign $ to jQuery, assuming you're using Firebug ( it keeps the native $ function which ISNT jquery ).
You can confirm this with:
alert( $ == jQuery )
If this isn't it, then make sure you aren't using multiple libraries that use $.
Unrelated: You can also do $(function(){ /* code */ }); instead of binding on window load.
Try this instead:
console.log(jQuery('#tab2').hasClass('selected'))
It looks suspiciously like the $ is given up but still in use, like Prototype in included in the page and jQuery.noConflict() was called (which means $ != jQuery when you're running commands in the console later).