$('.aClass')[index].addClass('newClass');
This is what I am trying to do, but it isn’t working, moreover its breaking the code after it.
What am I doing wrong ?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
When using the index like that, it returns the DOM element, thus no jQuery methods.
Use
.eq()instead to return the DOM element at that index while still wrapped by jQuery:There is also a selector
:eq, with slight differences to the method version in terms of form and usage. The index is part of the selector string, so if you use dynamic values, you have to cut the string:Additionally info: what you did was similar to a
.get()which returns the DOM element, not wrapped in jQuery, at that index: