Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selecting jquery elements with brackets []

Tags:

jquery

Why doesn't this work

$('div.note')[0].removeClass('hidden');

I get this error from firebug:

TypeError: note.removeClass is not a function
like image 347
Costa Michailidis Avatar asked Aug 09 '26 19:08

Costa Michailidis


1 Answers

$('div.note')[0] gives you a javascript object, not a jQuery object, and removeClass is a jQuery method. You need to convert it to a jQuery object before using jQuery methods.

Try this,

$($('div.note')[0]).removeClass('hidden');

or

$('div.note').eq(0).removeClass('hidden');
like image 61
Adil Avatar answered Aug 12 '26 09:08

Adil



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!