Reputation: 5025
<ul>
<li>First</li>
<li>Second</li>
<li>Third</li>
</ul>
Is it possible to add a class to the second li
listed above with jQuery, without a prexisting class or id?
Upvotes: 2
Views: 77
Reputation: 236032
Of course, you would go like
$('ul li:eq(1)').addClass('yourclassname');
Since the selector is zero-based, 1
represents the second node.
Reference: http://api.jquery.com/eq-selector/
Upvotes: 3