tags:

views:

55

answers:

2

When the page loads i replace the attributes of a specific object. Then in a few lines under(maybe directly under) i do another check which always seems to fail. So i tried

alert($('.myClass').hasClass('myClass'));

and by all logic shouldnt that always return true? I set a breakpoint in firebug and i can see the object with the new attribute however... why does this line fail?

+6  A: 

by all logic shouldnt that always return true?
It will return false if your selector matches no elements. Are you sure that's not the case? You can try this to check:

alert($('.myClass').length);
Nikita Rybak
ah! typo in the class name. I had to shuffle lines and write new code and i didnt know which part broke. Accept when the site allows
acidzombie24
+3  A: 

How about this?

var myclasses = $('.myClass');

alert(!myclasses.length || myclasses.hasClass('myClass'));
broady
Thats a funny way of telling me i am matching no elements :p +1 anyways
acidzombie24
Nikita Rybak
Oops. I meant: `!myclasses.length || myclasses.hasClass('myClass')` It's 3am :)
broady