这篇文章主要介绍“jquery如何清除兄弟元素”,在日常操作中,相信很多人在jquery如何清除兄弟元素问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”jquery如何清除兄弟元素”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!
jquery清除兄弟元素的方法:1、使用siblings()方法获取被选元素的所有兄弟元素;2、使用remove()方法删除获取到的兄弟元素,语法“$(selector).siblings().remove()”。

本教程操作环境:windows7系统、jquery1.10.2版本、Dell G3电脑。
jquery清除兄弟元素的方法
让他
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<style>
.siblings,.siblings *{
display: block;
border: 2px solid lightgrey;
color: lightgrey;
padding: 5px;
margin: 15px;
}
</style>
<script src="js/jquery-1.10.2.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("button").click(function() {
$("h3").siblings().remove();
});
});
</script>
</head>
<body>
<div class="siblings">div (父)
<p>p(兄弟元素)</p>
<span>span(兄弟元素)</span>
<h3>h3(本元素)</h3>
<h4>h4(兄弟元素)</h4>
<p>p(兄弟元素)</p>
</div>
<button>清除兄弟元素</button>
</body>
</html>

到此,关于“jquery如何清除兄弟元素”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注天达云网站,小编会继续努力为大家带来更多实用的文章!