jquery next nextAll nextUntil siblings的区别介绍

2019-12-24,,,

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>
<div class="first">
<a href="#">hhh</a>
<h1>这是一个标题</h1>
<p>这是一个test</p>
<p>这是一个test</p>
<p>这是一个test</p>
<p>这是一个test</p>
<div>hhha</div>
<p>这是一个test</p>
<p>这是一个test</p>
</div>
<script>
$(function(){
//$('p:first').next().css('background','red');
//$('p:first').nextAll().css('background','yellow');
//$('p:first').nextUntil('div').css({'font-size':20,background:'red'});
//$('p:first').siblings().css('background','yellow');
});
</script>
</body>
</html>

您可能感兴趣的文章:

  • jquery siblings获取同辈元素用法实例分析
  • jQuery中的siblings()是什么意思(推荐)
  • 浅谈jquery中next与siblings的区别
  • 有关jQuery中parent()和siblings()的小问题
  • jQuery siblings()用法实例详解
  • jquery遍历函数siblings()用法实例
  • jQuery中的siblings用法实例分析
  • jQuery中siblings()方法用法实例
  • jQuery prev ~ siblings选择器使用介绍
  • jquery 层次选择器siblings与nextAll的区别介绍
  • 仿jQuery的siblings效果的js代码
  • jQuery使用siblings获取某元素所有同辈(兄弟姐妹)元素用法示例

《jquery next nextAll nextUntil siblings的区别介绍.doc》

下载本文的Word格式文档,以方便收藏与打印。