Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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> 
like image 725
Chris Canal Avatar asked Oct 07 '08 13:10

Chris Canal


People also ask

How do I select all child elements except one in CSS?

To select all the children of an element except the last child, use :not and :last-child pseudo classes.

How do I select all except first in CSS?

The trick is very easy, in CSS we have the sibling selector ("+"), if i will make selector that choose "li + li" it will select all list-items except the first . That's all!

How do I not select the first child CSS?

Use the :not(selector) Selector Not to Select the First Child in CSS. We can use the :not(selector) selector to select every other element that is not the selected element. So, we can use the selector not to select the first child in CSS.


1 Answers

You should be able to use the "not" and "first child" selectors.

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

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

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

like image 151
twernt Avatar answered Oct 04 '22 06:10

twernt