English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

jQuery prevUntil() Method

jQuery Traversal Methods

The prevUntil() method returnsselectorandstopall previous elements at the same level between

Elements at the same level must have the same parent element.

If both parameters are omitted, this method will return all previous sibling elements, equivalent toprevAll()The method is the same.

Syntax:

$(selector).prevUntil(stop, selectorExpression)

Example

Return id="div-3"s all preceding sibling elements:

$(document).ready(function(){
  $("#div-3").prevUntil().css("background", "mediumpurple");
});
Test See‹/›

Return<dt id="term-2">All preceding siblings, up to the preceding<dt>:</dt>

$(document).ready(function(){
  $("#term-2").prevUntil("dt").css("background-color", "coral");
});
Test See‹/›

Parameter Value

ParameterDescription
stop(Optional) Selector expression, element, or jQuery object indicating where to stop searching for previously matched siblings
selectorExpression(Optional) Selector expression, element, or jQuery object to match the element
Note:To return multiple siblings, separate each expression with a comma

jQuery Traversal Methods