Reputation: 17
This code:
if (!jQuery('#item_SwitchBoard' + index).hasClass('invisible'))
JQuery('#item_SwitchBoard' + index).addClass('invisible');
throws exception: "Microsoft JScript - runtime error: Expected an object." (I hope that it is correct translation, because I have this message localized to my language)
but this code:
if (!jQuery('#item_SwitchBoard' + index).hasClass('invisible'))
document.getElementById('item_SwitchBoard' + index).className = 'invisible';
works without problem.
Why?
I don't understant it. I supposed that it should be same (or analogic) thing. And how is possible that
if (!jQuery('#item_SwitchBoard' + index).hasClass('invisible'))
works, but practicly same function:
JQuery('#item_SwitchBoard' + index).addClass('invisible');
say to me that "Expected an object.". This object has been taken by hell during milisecond or what?
I use getElementById if it works, but I interested why JQuery not works correctly in all cases. Any ideas?
It is 1.4.2 version of JQuery.
Upvotes: 1
Views: 551
Reputation: 17525
Because capitalization is important. You need to use jQuery
, not JQuery
.
Upvotes: 0
Reputation: 18237
if (!jQuery('#item_SwitchBoard' + index).hasClass('invisible'))
JQuery('#item_SwitchBoard' + index).addClass('invisible');
Your second line has JQuery
when it should be jQuery
if (!jQuery('#item_SwitchBoard' + index).hasClass('invisible'))
jQuery('#item_SwitchBoard' + index).addClass('invisible');
Upvotes: 0
Reputation: 18036
Could it be the capital J in JQuery? jQuery refers to an object while JQuery does not refer to an object.
Upvotes: 9