- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to find all siblings of currently selected object in jQuery?
To find all siblings of currently selected object in jQuery, use the siblings() method. The siblings( [selector] ) method gets a set of elements containing all of the unique siblings of each of the matched set of elements.
Here is the description of all the parameters used by this method −
- selector − This is optional selector to filter the sibling Elements with.
Example
You can try to run the following code to learn how to find all siblings:
<html> <head> <title>jQuery siblings() method</title> <script src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> <script> $(document).ready(function(){ $("p").siblings('.selected').addClass("highlight"); }); </script> <style> .highlight { background:yellow; } </style> </head> <body> <div><span>Hello</span></div> <p class = "selected">Hello Again</p> <p>And Again</p> </body> </html>
Advertisements