In this article, we will discuss how to select all sibling elements of an element using jQuery. To select all sibling elements of an element, we will use the siblings() method.
The siblings() method is used to find all sibling elements of the selected element. The siblings are those having the same parent element in DOM Tree.
This function accepts an optional parameter “function” that is going to select all siblings of the selected elements. It returns all the siblings of the selected element.
Approach: First, we will create the main div container, and inside the main container, we will add two div containers. When the user clicks on the button, the siblings() method is called and it selects the siblings of the section1 class container. After selecting the siblings, we add some CSS properties to them.
Example: In this example, we will use the above approach.
Please Login to comment...