jQuery prev() method
Example
Return each with class name "start"
$
(
document
)
.
ready
(
function
(
)
{
$
(
"
li.start
"
)
.
prev
(
)
.
css
(
{
"
color
"
:
"
red
"
,
"
border
"
:
"
2px solid red
"
}
)
;
}
)
;
Result:
- li (sibling)
- li (sibling)
- li (sibling with class name "start")
- li (sibling)
- li (sibling)
Try it »
Definition and Usage
The prev() method returns the previous sibling element of the selected element.
Sibling elements are elements that share the same parent element.
**Note:** This method returns only one element.
**DOM Tree:** This method traverses backward along the previous sibling elements of the DOM element.
Related methods:
- prevAll() - returns all sibling elements before the selected element
- prevUntil() - returns all sibling elements before each element between two given arguments
Syntax
$(
selector
).prev(
filter
)
| Parameters | Description |
|---|---|
| filter | Optional. Specifies a selector expression to narrow down the search for the previous sibling element. |
More examples
the previous sibling element of the
How to select each
How to select each
the previous sibling element of the.
Narrow down the search
How to select each
jQuery Traversal Methods