---
title: "Select all next sibling via jQuery"  
description: "Select all next sibling via jQuery"  
author: "Ethan Karla"  
published: 2021-07-29  
updated: 2023-06-12  
canonical: https://www.mindstick.com/forum/156678/select-all-next-sibling-via-jquery  
category: "jquery"  
tags: ["jquery"]  
reading_time: 1 minute  

---

# Select all next sibling via jQuery

How to [select](https://www.mindstick.com/forum/160534/orderby-then-select-vs-select-then-orderby-performance) all next sibling via jQuery?

\

## Replies

### Reply by Aryan Kumar

Sure, here is how you can select all next siblings via jQuery:

Code snippet

```plaintext
// Select all `li` elements
var lis = $('li');

// Get all next siblings of each `li` element
var nexts = lis.nextAll();
```

The `nextAll()` method returns all following siblings of each element in the set of matched elements, optionally filtered by a selector. In this case, we are not filtering the results, so all next siblings will be returned.

The `nexts` variable will now contain a jQuery object that represents all of the next siblings of the `li` elements. You can then use this object to do whatever you need to do with the next siblings, such as:

- Loop through the next siblings and print their text content:

Code snippet

```plaintext
nexts.each(function() {
  console.log($(this).text());
});
```

- Change the background color of all next siblings to red:

Code snippet

```plaintext
nexts.css('background-color', 'red');
```

- Hide all next siblings:

Code snippet

```plaintext
nexts.hide();
```

- Do something else entirely!


---

Original Source: https://www.mindstick.com/forum/156678/select-all-next-sibling-via-jquery

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
