在本文为大家详细介绍下jquery next nextall nextuntil siblings的区别,感兴趣的朋友可以参考下
next:紧挨着$('')的一个元素
nextAll:在$('')以后的所有的同辈元素
nextUntil:until有直到。。。之前的意思,所以他表示$('')以后的所有的同辈元素,不过要在nextUntil参数之前,不包括匹配的元素本身
sibings:$('')前后的所有同辈元素
简单理解就是,next就是找他的弟弟/妹妹,nextAll就是找他所有的弟弟/妹妹,nextUntil就是找比他小一定年龄的弟弟/妹妹,siblings就是找他所有的哥哥/姐姐,还有他的所有的弟弟/妹妹。所以同理的同辈关系,prev,prevAll ,prevUntil
下面是简单的测试代码
代码如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>
Document
</title>
<script type='text/
javascript
' src='http://code.jquery.com/jquery-1.9.1.min.js'></script>
</head>
<body>
<p class="first">
<a href="#">hhh</a>
<h1>这是一个标题</h1>
<p>这是一个test</p><div class="aritcle_card flexRow">
<div class="artcardd flexRow">
<a class="aritcle_card_img" href="/ai/1587" title="讯飞听见会议"><img
src="https://img.php.cn/upload/ai_manual/000/000/000/175680266822953.jpg" alt="讯飞听见会议" onerror="this.onerror='';this.src='/static/lhimages/moren/morentu.png'" ></a>
<div class="aritcle_card_info flexColumn">
<a href="/ai/1587" title="讯飞听见会议">讯飞听见会议</a>
<p>科大讯飞推出的AI智能会议系统</p>
</div>
<a href="/ai/1587" title="讯飞听见会议" class="aritcle_card_btn flexRow flexcenter"><b></b><span>下载</span> </a>
</div>
</div>
<p>这是一个test</p>
<p>这是一个test</p>
<p>这是一个test</p>
<p>hhha</p>
<p>这是一个test</p>
<p>这是一个test</p>
</p>
<script>
$(function(){
//$('p
:first
').next().css('
background
','red');
//$('p:first').nextAll().css('background','yellow');
//$('p:first').nextUntil('p').css({'
font-size
':20,background:'red'});
//$('p:first').siblings().css('background','yellow');
});
</script>
</body>
</html>









