English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The prevAll() method returns all sibling elements preceding the selected element.
Elements at the same level must have the same parent element.
Syntax:
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 | Description |
---|---|
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 |