jQuery 删除某个元素之后的所有元素

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6641365/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 21:10:29  来源:igfitidea点击:

Remove all elements after certain element

jquery

提问by Damien Roche

My code is:

我的代码是:

<div id="wrap">
  <div id="element1" class="ewrap"></div>
  <div id="element2" class="ewrap"></div>
  <div id="element3" class="ewrap"></div>
  <div id="element4" class="ewrap"></div>
  <div id="element5" class="ewrap"></div>
</div>

How would I dynamicallyremove all elements after element1?

之后如何动态删除所有元素element1

回答by Darin Dimitrov

You could use the .nextAll()method:

您可以使用以下.nextAll()方法:

$('#element1').nextAll('div').remove();