Javascript examples for jQuery:List
Add a red color to the direct child of <ul> with children() method.
<!DOCTYPE html> <html> <head> <style> .ancestors * {/*from ww w . ja v a2s. co m*/ display: block; border: 2px solid lightgrey; color: blue; 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").children().css({"color": "red"}); }); </script> </head> <body> <div class="ancestors"> <div style="width:500px;">div <ul>ul <li>li <span>span</span> </li> </ul> </div> </div> </body> </html>