siblings() next() nextAll() nextUntil() prev() prevAll() prevUntil() 在 DOM 树中水平遍历

$(document).ready(function(){
  $("h2").siblings();
});
拿到h2标签的所有的同级元素什么标签都可以

$(document).ready(function(){
  $("h2").siblings("p");
});
拿到h2标签的所有的同级p标签元素

$(document).ready(function(){
  $("h2").next();
});
拿到h2标签的同级的下一个元素


$(document).ready(function(){
  $("h2").nextAll();
});
拿到h2标签的同级的后面的所有元素

$(document).ready(function(){
  $("h2").nextUntil("h6");
});
拿到h2标签后面的和h6前面的所有的元素


 prev(), prevAll() & prevUntil() 与上面的方法类似,只不过方向相反而已:它们返回的是前面的同胞元素

原文地址:https://www.cnblogs.com/zouyun/p/7687043.html