English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The prev() method returns the preceding sibling element that is placed before the selected element.
Sibling elements must have the same parent element.
Note: This method returns only one element.
$("selector").prev("selectorExpression")
Return element with id="div-2element's previous sibling element:
$("document").ready(function(){ $("#div-2").prev().css("background", "mediumpurple"); });Test See‹/›
Return the previous sibling element of each DIV element:
$("document").ready(function(){ $("div").prev().css("background", "lightblue"); });Test See‹/›
Return the previous sibling element of each DIV element:
$("document").ready(function(){ $("div").prev("p").css("background", "lightblue"); });Test See‹/›
Parameter | Description |
---|---|
selectorExpression | An optional selector expression, element, or jQuery object to match elements |