jQuery删除所有元素,直到id ='what'found [英] jQuery remove all elements until id='whatever' found

查看:66
本文介绍了jQuery删除所有元素,直到id ='what'found的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

需要删除开始代码中的所有代码

Need to remove all the code from the start tag to the next

我试过这个

$('#page1').remove();

但这只会删除标签之间的内容。

But that only removes what's between the tag.

我不知道page1和page2标签之间还有什么,因为代码是根据页面上的表单元素类型动态添加的。

And I don't know what else could be between the page1 and page2 tags as the code is dynamically added based on the types of form elements on the page

<div id='page1' name='page1'>
 ...
</div> 
<div id='another element' />
<div id=yet 'another element' />
...
<!-- Need to remove from page1 to here -->
<div id='page2' name='page2'>
 ...
</div>


推荐答案

假设您要删除 page1 以及 page2 之前的所有内容你可以这样做:

Assuming you want to remove page1 and everything until page2 you can do this:

$("#page1").nextUntil("#page2").andSelf().remove();

关于jsfiddle的示例

Example on jsfiddle

这篇关于jQuery删除所有元素,直到id ='what'found的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆