I am using jQuery and put this code in my javascript:
function HideMe(itemID) {
var myDiv = 'item_' + itemID;
$(myDiv).fadeOut("slow");
}
But its giving me this error: fadeOut
is not a function.
This will happen if you're using the "slim" version of jQuery. Only the "full" version of jQuery includes animation effects.
Try grabbing the "full" version of jQuery from the jQuery downloads page and including that in your page (or including a full version of jQuery from a CDN from your page).
Do you have another javascript library on that page? It seems you have the hide
function, and the $
defined (prototype, for example, also has an hide
function).
If that is the case, try:
jQuery("#item_0").fadeOut("slow");
I had this error because I was using a slim version of jQuery. If you download the full version you should be okay.
Even if the selector didn't return any items in the collection the function call would have worked (not generated this error anyway) if jQuery was loaded correctly. Either there is a conflict in the page, or it didn't load at all. You can try
jQuery(myDiv).fadeOut("slow");
or look into why jQuery hasn't been loaded.
P.S.: don't forget the #
in the selector if selecting by id.
It happened to me because of slim version of Jquery library. Full version of Jquery library includes animation.
Jquery CDN available at https://code.jquery.com/
Also, you probably forgot a #
in the selector (unless you've got something like <item_1 />
in the markup).
var myDiv = '#item_' + itemID;
jQuery uses CSS selectors to search for elements, so without the #
, you'd get every element with the tag item_x
instead of the ID.
It looks like jquery is not correctly attached to the page.
Check your linking to jQuery.
Try keeping it inside
$(document).ready(function(){
// your code. and don't forget the '#' in front of item.
});
Looks like you're trying to call the function before jQuery / the DOM loads.
You have liDiv
instead of myDiv
. Try:
function HideMe(itemID) {
var myDiv = 'item_' + itemID;
$(myDiv).fadeOut("slow");
}
On moving a .html template to a wordpress one, I found this popping up regularly.
Two reasons, and the console error can be deceptive:
The error in the console can send you down the wrong path. It MIGHT not be the real issue. First reason for me was the order in which you have set your .js files to load. In html easy, put them in the same order as the theme template. In Wordpress, you need to enqueue them in the right order, but also set a priority if they don't appear in the right order,
Second thing is are the .js files in the header or the footer. Moving them to the footer can solve the issue - it did for me, after a day of trying to debug the issue. Usually doesn't matter, but for a complex page with lots of js libraries, it might!