- 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
How to select ALL children (in any level) from a parent in jQuery?
To select all children from a parent in jQuery, use the find() method. You can try to run the following code to select ALL children in any level −
Example
<!DOCTYPE html> <html> <head> <style> .myclass * { display: block; border: 2px solid lightgrey; color: lightgrey; padding: 5px; margin: 15px; } </style> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script> $(document).ready(function(){ $('ul').find('*').css({"color": "red", "border": "2px solid green"}); }); </script> </head> <body> <div class="myclass"> <div style="width:400px;">div - great-grandparent <ul>ul <li>li- child - level 1 <ul>ul- child - level 2 <li>li- child - level 3</li> <li>li- child - level 3</li> </ul> </li> </ul> </div> </div> </body> </html>
Advertisements