> For the complete documentation index, see [llms.txt](https://jscula.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://jscula.gitbook.io/docs/traversal/.prev.md).

# .prev()

Returns the previous sibling element.

## `$(selector).prev()`

Returns the **previous sibling element** of the selected element.

### Syntax

```javascript
$(selector).prev();
```

### Example

```html
<div>
  <div id="one"></div>
  <div id="two"></div>
</div>
```

```javascript
$('#two').prev();
// returns <div id="one">
```

### Use cases

Use `.prev()` to work with content immediately before an element:

* Mark the previous step as complete.
* Read a label before an input.
* Update the item before a selected list entry.

### More examples

Mark the previous step as complete:

```javascript
$('#current-step').prev().addClass('complete');
```

Show a message in the sibling element before an input:

```javascript
$('#email').prev().text('Email address');
```

Select the previous item in a list:

```javascript
$('#selected-item').prev().addClass('selected');
```
