jQuery | siblings() with Examples
The siblings() is an inbuilt method in jQuery which is used to find all siblings elements of the selected element. The siblings are those having same parent element in DOM Tree. The DOM (Document Object Model) is a World Wide Web Consortium standard. This is defines for accessing elements in the DOM tree.
Here, the selector is the selected element whose siblings are going to be found.
Parameters: It accepts an optional parameter “function” which are going to say that which siblings should be selected out of all the siblings.
Return Value : It returns all the siblings of the selected element.
In the below code, no parameter is passed to the siblings() function.
In the above code, all the siblings of “h2” get highlighted.
In the below code, an optional parameter for the function is used to filter the search for siblings.
In the above code, all the siblings of “h2” with element name “span” get selected.