Chris Canal Chris Canal - 5 years ago 138
Javascript Question

Select all child elements except the first

Say I have the following:

<ul>
<li>First item</li>
<li>Second item</li>
<li>Third item</li>
</ul>


How would I select all the child elements after the first one using jQuery? So I can achieve something like:

<ul>
<li>First item</li>
<li class="something">Second item</li>
<li class="something">Third item</li>
</ul>

Answer Source

You should be able to use the "not" and "first child" selectors, like this:

$("li:not(:first-child)").addClass("something");

http://docs.jquery.com/Selectors/not

http://docs.jquery.com/Selectors/firstChild

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download