i have the following html:
<div class="well sidebar-nav">
<ul class="nav nav-list">
<li class="nav-header">head</li>
<li><a href="index.html"><i class="icon-cog"></i> index</a></li>
<li><a href="contacts.html"><i class="icon-globe"></i> contacts</a></li>
....
i’d like to put the class='active' in one of the <li> but with jquery.
i know that i’ve to use something like this:
function select() {
$("li").addClass("active");
}
Use the
:eq()selector:The number passed should be zero based, so that the second
liis accessed by using:eq(1).For better performance, you should split up the selector, and use the
.eq()function: