jQuery nextUntil() 方法

jQuery 教程 · 2019-03-28 08:59:39

实例

返回在类名为 "start" 和 "stop" 的两个 <li> 元素之间的所有同级元素:

$(document).ready(function(){
$("li.start").nextUntil("li.stop").css({"color":"red","border":"2px solid red"});
});

结果:

    ul (parent)
  • li (sibling)
  • li (sibling)
  • li (sibling with class name "start")
  • li (sibling)
  • li (sibling)
  • li (sibling)
  • li (sibling with class name "stop")

定义和用法

nextUntil() 方法返回 selectorstop 之间的每个元素之后的所有同级元素。

同级元素是共享相同父元素的元素。

DOM 树:该方法沿着 DOM 元素的同级元素向前遍历。

注意:如果两个参数都为空,该方法将返回元素之后的所有同级元素(与 nextAll() 方法相同)。

相关方法:

  • next() - 返回被选元素的后一个同级元素
  • nextAll() - 返回被选元素之后的所有同级元素

语法

$(selector).nextUntil(stop,filter)

参数 描述
stop 可选。表示在哪里停止搜索元素之后匹配的同级元素的选择器表达式、元素、jQuery 对象。
filter 可选。规定缩小搜索介于 selectorstop 之间的同级元素范围的选择器表达式。

注意:如需返回多个同级元素,请使用逗号分隔每个表达式。

点击查看所有 jQuery 教程 文章: https://www.codercto.com/courses/l/35.html

查看所有标签

Building Social Web Applications

Building Social Web Applications

Gavin Bell / O'Reilly Media / 2009-10-1 / USD 34.99

Building a social web application that attracts and retains regular visitors, and gets them to interact, isn't easy to do. This book walks you through the tough questions you'll face if you're to crea......一起来看看 《Building Social Web Applications》 这本书的介绍吧!

SHA 加密
SHA 加密

SHA 加密工具

Markdown 在线编辑器
Markdown 在线编辑器

Markdown 在线编辑器

HEX HSV 转换工具
HEX HSV 转换工具

HEX HSV 互换工具