Example of Child Selector in jQuery
March 31, 2013
Child Selector in jQuery works like parent > child. Child Selector selects all the immediate child of the specified parent. On the selection, we can add CSS or can perform other functionality.In the below example, we have ul>li relation. Here ul is parent and li is child.
<!DOCTYPE html> <html> <head> <script src="http://code.jquery.com/jquery-1.9.1.js"></script> </head> <body> <ul class="cls"> <li>A</li> <li>B <ul><li>X</li> <li>Y</li> </ul> </li> <li>C</li> </ul> <script>$("ul.cls > li").css("border", "2px double green");</script> </body> </html>
Output
- A
-
B
- X
- Y
- C