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

jQuery prevAll() Method

jQuery Traversal Methods

The prevAll() method returns all sibling elements preceding the selected element.

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

Syntax:

Syntax:

Example

Return id="div-3elements' all previous sibling elements:

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

Return all previous sibling elements of each DIV element:

$("document").ready(function(){
  $("div").prevAll().css("background", "lightblue");
});
Test and see‹/›

Return all previous sibling elements of each DIV element:

$("document").ready(function(){
  $("div").prevAll("p").css("background", "lightblue");
});
Test and see‹/›

Parameter Value

ParameterDescription
selectorExpression(Optional) A selector expression, element, or jQuery object to match the element with
Note:To return multiple siblings, separate each expression with a comma

jQuery Traversal Methods