Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
89
rated 0 times [  93] [ 4]  / answers: 1 / hits: 10342  / 8 Years ago, wed, april 20, 2016, 12:00:00

I want to add class for the third element in javascript. I have this structure:



<ul class=products-grid row four-columns first>
<li class=item></li>
<li class=item></li>
<li class=item add-class-here></li>
<li class=item></li>
</ul>

More From » jquery

 Answers
3

Try this :



$( ul.products-grid li:nth-child(3)).addClass(new_css_class);


Reference : https://api.jquery.com/nth-child-selector/


[#29299] Tuesday, April 19, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jillalanisg

Total Points: 484
Total Questions: 98
Total Answers: 89

Location: Vanuatu
Member since Wed, Oct 14, 2020
4 Years ago
;