Latest web development tutorials

jQuery prevUntil () 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 with class name "stop")
  • li (sibling)
  • li (sibling)
  • li (sibling)
  • li (sibling with class name "start")
  • li (sibling)
  • li (sibling)

try it"

Definition and Usage

prevUntil () method returns all siblings of each element between the selector and stop before.

Sibling elements are elements that share the same parent element.

DOM tree: This method traverses back along the sibling elements of the DOM element.

Note: If both arguments are null, the method returns all elements sibling elements before (and prevAll () in the same manner).

Related methods:

  • the PREV () - Returns selected elements of the previous sibling element
  • prevAll () - Returns the previous sibling of the selected element all elements

grammar

$(selector).prevUntil( 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 before the.

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 before the.


jQuery traversal methods jQuery traversal methods