jQuery siblings()
Method
The jQuery siblings()
method is used to select all the sibling elements of a selected element. Siblings are the elements that share the same parent as the selected element.
Syntax
The basic syntax for using the siblings()
method in jQuery is as follows:
$(selector).siblings(filter);
Here, selector
is the element you want to select the siblings for and filter
is an optional parameter to filter the siblings based on a specific criteria.
Use
The siblings()
method is useful when you want to apply a certain style or behavior to all the sibling elements of a selected element. For example, you might want to highlight all the links in the sibling list items of a navigation menu when the user hovers over a particular list item.
Example
Here is an example of using the siblings()
method to select all the sibling elements of a selected element and apply a class to them: