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

jQuery prev() Method

jQuery Traversal Methods

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.

Syntax:

$("selector").prev("selectorExpression")

Example

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 Value

ParameterDescription
selectorExpressionAn optional selector expression, element, or jQuery object to match elements

jQuery Traversal Methods