Reputation: 1
How can I get all li
elements starting from second item (level_2
) onwards using jQuery?
<ul>
<li class="item level_1">text1</li>
<li class="item level_2">text2</li>
<li class="item level_3">text3</li>
<li class="item level_4">text4</li>
<li class="item level_3">text5</li>
<li class="item level_2">text2</li>
<li class="item level_3">text3</li>
</ul>
Upvotes: 0
Views: 55
Reputation: 79830
I prefer using .slice
.
var $li = $('ul li');
var $li_from_second = $li.slice(1);
Upvotes: 0
Reputation: 318182
You can use the :gt() selector and select all li
with an index greater than zero :
$('li:gt(0)')
Upvotes: 0
Reputation: 4501
There are several ways to filter a list of elements, in this case .not
will work well for you.
$('li').not(':first-child');
Upvotes: 1
Reputation: 17434
Look into using nextAll()
.
$("li").eq(0).nextAll("li");
This will select all <li>
s starting with the second one.
Upvotes: 2