tags:

views:

119

answers:

6

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.

Can anyone help me?

Thanks in advance Marc V

+1  A: 

You have liDiv instead of myDiv. Try:

function HideMe(itemID) {
    var myDiv = 'item_' + itemID;
    $(myDiv).fadeOut("slow");
}
Tomas Lycken
my mistake .....i used myDiv, but it was written wrong here, its not working using myDiv though.
Marc V
+2  A: 

It looks like jquery is not correctly attached to the page.

Check your linking to jQuery.

Adrian
It's attached because I am able to use $(myDiv).hide(); function perfectly
Marc V
You are linking to jQuery in the Head section? Are you using another javascript library that also uses the $ character as an identifier? ( OpenLayers is one such library)
Adrian
+3  A: 

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.

moff
Doesn't matter though, this error doesn't pop up if jQuery is loaded correctly.
altCognito
You're absolutely right, I just posted this if it *still* didn't work. I thought the variable naming was the problem, though I now see I was wrong.
moff
+4  A: 

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.

altCognito
+1, Good point.
Ayman Hourieh
How can i check that jQuery is loaded or not. I am able to use $(myDiv).hide(); function perfectly. but not fadeOut
Marc V
+1  A: 

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.

Sudhir Jonathan
when i use $(document).ready(function() { } its saying $(document).ready is not a function
Marc V
+2  A: 

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");
Kobi
Thanx a lot........ you save my day
Marc V