---
title: "Select all previous siblings via jQuery"  
description: "Select all previous siblings via jQuery"  
author: "Ethan Karla"  
published: 2021-07-29  
updated: 2023-06-14  
canonical: https://www.mindstick.com/forum/156675/select-all-previous-siblings-via-jquery  
category: "jquery"  
tags: ["jquery"]  
reading_time: 2 minutes  

---

# Select all previous siblings via jQuery

How to [select](https://www.mindstick.com/forum/160534/orderby-then-select-vs-select-then-orderby-performance) all [previous](https://yourviews.mindstick.com/view/81421/unlock-2-0-is-just-like-previous-corona-lockdowns) siblings via jQuery?\

## Replies

### Reply by Aryan Kumar

Sure, you can use the prevAll() method in jQuery to select all previous siblings of an element. The prevAll() method returns a jQuery object containing all of the previous siblings of the selected element.

Here is an example of how to use the prevAll() method to select all previous siblings of an element:

Code snippet

```plaintext
// Select the element with the ID "myElement"
var myElement = $("#myElement");

// Get all of the previous siblings of myElement
var previousSiblings = myElement.prevAll();

// Loop through the previousSiblings collection and do something with each element
for (var i = 0; i < previousSiblings.length; i++) {
  // Do something with the current element
}
```

The prevAll() method can also be used to filter the previous siblings of an element by a selector. For example, the following code will select all of the previous siblings of the element with the ID "myElement" that are also div elements:

Code snippet

```plaintext
// Select the element with the ID "myElement"
var myElement = $("#myElement");

// Get all of the previous siblings of myElement that are div elements
var previousSiblings = myElement.prevAll("div");

// Loop through the previousSiblings collection and do something with each element
for (var i = 0; i < previousSiblings.length; i++) {
  // Do something with the current element
}
```


---

Original Source: https://www.mindstick.com/forum/156675/select-all-previous-siblings-via-jquery

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
