Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript jQuery text() works on DOM object, but, not addClass() Reply To: jQuery text() works on DOM object, but, not addClass()

#164380
noahgelman
Participant

When you select something with jQuery, jQuery puts it in an array. so el is an array, and tabs is an array. And you can perform jQuery things on this array.

When you use something like tabs[0] or tabs.get(0) you’re selecting an element of the array in a normal javascript and NON-jQuery way. This is why you can’t use addClass() because its no longer a jQuery object.

So how do we select an element in a jQuery way? There’s a couple ways. You can do something like $(tabs[0]) or $(tabs.get(0)) which will re-select the new javascript element with jQuery.

Or you can just use the .eq() property.

Try tabs.eq(0) This is like get() which you used, but it keeps the selected element in jQuery.

I hope this helps.