Easy Tutorial
❮ Jquery Dom Add Event Focusout ❯

jQuery prev() Method

jQuery Traversing Methods

Example

Return the previous sibling element of each <li> element with the class name "start":

$(document).ready(function(){
    $("li.start").prev().css({"color":"red","border":"2px solid red"});
});

Result:


Definition and Usage

The prev() method returns the previous sibling element of the selected element.

Sibling elements are elements that share the same parent.

Note: This method only returns one element.

DOM Tree: This method traverses to the previous sibling element of the DOM elements.

Related methods:


Syntax

Parameter Description
filter Optional. Specifies a selector expression to narrow down the search for the previous sibling element.

More Examples

Select the previous sibling element of each <div> element

Narrow down the search


jQuery Traversing Methods

❮ Jquery Dom Add Event Focusout ❯