其他分享
首页 > 其他分享> > jquery--遍历【同胞】

jquery--遍历【同胞】

作者:互联网

原文链接:https://www.runoob.com/jquery/jquery-traversing-siblings.html

在 DOM 树进行水平遍历:

siblings() 方法

返回 <h2> 的所有同胞元素:


$(document).ready(function(){
  $("h2").siblings();
});

返回属于 <h2> 的同胞元素的所有 <p> 元素:


$(document).ready(function(){
  $("h2").siblings("p");
});

next() 方法

返回 <h2> 的下一个同胞元素:


$(document).ready(function(){
  $("h2").next();
});

nextAll() 方法

返回 <h2> 的所有跟随的同胞元素:


$(document).ready(function(){
  $("h2").nextAll();
});

nextUntil() 方法

返回介于 <h2> 与 <h6> 元素之间的所有同胞元素:


$(document).ready(function(){
  $("h2").nextUntil("h6");
});

prev(), prevAll() & prevUntil() 方法

prev(), prevAll() 以及 prevUntil() 方法的工作方式与上面的方法类似,只不过方向相反而已:它们返回的是前面的同胞元素(在 DOM 树中沿着同胞之前元素遍历,而不是之后元素遍历)

 

 

标签:jquery,function,遍历,h2,元素,ready,同胞,siblings
来源: https://blog.csdn.net/qq_42176520/article/details/100654221