- Trending Categories
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
jQuery element ~ siblings Selector
The element ~ siblings selector in jQuery is used to select all elements that are siblings of the specified "element".
Syntax
The syntax is as follows −
("ele ~ siblings")
Above, the parameter ele is any valid selector, whereas siblings are the siblings of the ele parameter.
Example
Let us now see an example to implement the jQuery element ~ siblings selector −
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script> <script> $(document).ready(function(){ $("div ~ p").css("color", "orange"); }); </script> <style> div { border:1px solid black; padding:10px; } </style> </head> <body> <h2>Demo Heading</h2> <div> <p>This is demo text.</p> <span>span outside p element</span> <p>This is demo text.</p> </div> <p>p next to div.</p> <p>This is demo text.</p> <div> <p>This is demo text.</p> <p>This is demo text. <span>span inside p element.</span></p> <p>This is demo text.</p> </div> </body> </html>
Output
This will produce the following output−
- Related Articles
- jQuery element Selector
- jQuery element + next Selector
- jQuery Traversing Siblings
- jQuery siblings() with Examples
- How to find all the siblings for the clicked element in jQuery?
- How to get a DOM Element from a jQuery Selector?
- How to exclude first and second element from jQuery selector?
- jQuery :button Selector
- jQuery :checkbox Selector
- jQuery :checked Selector
- jQuery :contains() Selector
- jQuery :disabled Selector
- jQuery :empty Selector
- jQuery :enabled Selector
- jQuery :even Selector

Advertisements