---
title: "Use of sibling method in jQuery"  
description: "Use of sibling method in jQuery"  
author: "Ethan Karla"  
published: 2021-07-28  
updated: 2023-06-14  
canonical: https://www.mindstick.com/forum/156654/use-of-sibling-method-in-jquery  
category: "jquery"  
tags: ["jquery"]  
reading_time: 2 minutes  

---

# Use of sibling method in jQuery

What is the use of sibling [method in jQuery](https://www.mindstick.com/forum/156655/trim-method-in-jquery)?\

## Replies

### Reply by Aryan Kumar

Sure, the sibling() [method](https://www.mindstick.com/forum/166/webservice-method) in jQuery is used to select all sibling elements of the selected element. Sibling elements are elements that share the same parent.

The sibling() method takes no arguments and returns a jQuery object containing all of the sibling elements of the selected element.

Here is an example of how to use the sibling() method:

Code snippet

```plaintext
// Select all of the siblings of the element with the id 'my-element'
var siblings = $('#my-element').siblings();
```

The siblings object can be used to perform a variety of tasks, such as:

- Selecting all of the sibling elements of an element
- Adding or removing an event handler from all of the sibling elements of an element
- Changing the style of all of the sibling elements of an element
- Getting or setting the value of an attribute on all of the sibling elements of an element

The sibling() method is a powerful tool that can be used to easily select all of the sibling elements of an element.

Here are some additional examples of how the sibling() method can be used:

// Change the color of all of the siblings of the element with the id 'my-element' to red $('#my-element').siblings().css('color', 'red');

// Add an event handler to all of the siblings of the element with the id 'my-element' to prevent them from being deleted $('#my-element').siblings().on('click', function() { return false; });

// Get the value of the href attribute on all of the siblings of the element with the id 'my-element' var hrefs = $('#my-element').siblings().attr('href');


---

Original Source: https://www.mindstick.com/forum/156654/use-of-sibling-method-in-jquery

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
