jquery - Select all elements after a certain eleme

2019-01-11 17:06发布

I have a list similar to below and would like to only select all of the elements after the #everything_after element.

<div id="container">
  <div class="something"></div>
  <div class="something"></div>
  <div class="something"></div>
  <div class="something"></div>
  <div class="something"></div>
  <div id="everything_after"></div>
  <div class="something"></div>
  <div class="something"></div>
  <div class="something"></div>
  <div class="something"></div>
  <div class="something"></div>
</div>

4条回答
趁早两清
2楼-- · 2019-01-11 17:17

selects all the elements

$('#element *').attr('selected','selected');
查看更多
做个烂人
3楼-- · 2019-01-11 17:32

CASE-1: when the id="" or the class="" selector is known:

$("#everything_after").nextAll();
//selects any of the next sibling elements, like <div>, <p>, <i>... etc tags.

//--or--
$("#everything_after").nextAll("div");
//selects only the next sibling <div> tags;

CASE-2: when the index of the item is known:

$("#container > div:nth-child(6)").nextAll();
//--or--
$("#container > div:eq(5)").nextAll();
查看更多
Bombasti
4楼-- · 2019-01-11 17:33

You can use nextAll to get the following divs.

Try:

$("#everything_after").nextAll();
查看更多
Rolldiameter
5楼-- · 2019-01-11 17:39

See: CSS3 General Siblings Selector

http://reference.sitepoint.com/css/generalsiblingselector

$("#everything_after ~ div")...
查看更多
登录 后发表回答