Latest web development tutorials

jQuery nextUntil () method

jQuery traversal methods jQuery traversal methods

Examples

Returns all sibling elements between the class called "start" and "stop" two <li> element:

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

result:

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

try it"

Definition and Usage

All siblings nextUntil () method returns each element between the selector and stop after.

Sibling elements are elements that share the same parent element.

DOM tree: This method along siblings DOM element traversal forward.

Note: All siblings (and if both parameters are null, the method returns the element after nextAll () in the same manner).

Related methods:

  • Next () - Returns after being a sibling element of the selected element
  • nextAll () - Returns all sibling elements after the selected element

grammar

$(selector).nextUntil( stop,filter )

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

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

Examples

More examples

Narrow your search
Two parameters are used to filter the search for sibling elements between each element of the argument between the two later on.

Return more than one sibling elements
How to return multiple sibling elements between two parameters.

DOM
Use DOM element instead of the selector to return to all sibling elements between two given parameters.

Use DOM with two parameters
Use DOM with two parameters instead choose to filter the search for sibling elements between each element of the argument between the two later on.


jQuery traversal methods jQuery traversal methods