删除方法:1、使用“$(selector).next().remove()”语句删除指定元素后的第一个兄弟节点;2、使用“$(selector).nextAll().remove()”语句删除指定元素后的所有兄弟节点。

本教程操作环境:windows7系统、jquery1.10.2版本、Dell G3电脑。
jquery删除指定元素后的兄弟节点的方法
1、利用next()和remove()方法
使用next()获取被选元素的下一个兄弟节点。
使用remove()方法删除获取到的兄弟元素
html>
<meta><style>
.siblings,.siblings *{
display: block;
border: 2px solid lightgrey;
color: lightgrey;
padding: 5px;
margin: 15px;
}
</style><script></script><script>
$(document).ready(function() {
$("button").click(function() {
$("h2").next().remove();
});
});
</script><div>div (父)
<p>p(兄弟元素)</p>
<span>span(兄弟元素)</span>
<h2>h2(本元素)</h2>
<h3>h3(兄弟元素)</h3>
<p>p(兄弟元素)</p>
</div>
<button>清除兄弟元素</button>

jQuery 1.12.4是jQuery 1.x系列的最后一个正式稳定版本,由jQuery团队于2016年发布。该版本主要面向需要兼容旧版浏览器环境的网站和Web应用,尤其适用于仍需支持Internet Explorer 6、Internet Explorer 7、Internet Explorer 8等老旧浏览器的项目。
2、利用nextAll()和remove()方法
使用next()获取被选元素的所有兄弟节点。
使用remove()方法删除获取到的兄弟元素
html>
<meta><style>
.siblings,.siblings *{
display: block;
border: 2px solid lightgrey;
color: lightgrey;
padding: 5px;
margin: 15px;
}
</style><script></script><script>
$(document).ready(function() {
$("button").click(function() {
$("h2").nextAll().remove();
});
});
</script><div>div (父)
<p>p(兄弟元素)</p>
<span>span(兄弟元素)</span>
<h2>h2(本元素)</h2>
<h3>h3(兄弟元素)</h3>
<p>p(兄弟元素)</p>
</div>
<button>清除兄弟元素</button>

相关视频教程推荐:jQuery教程(视频)










