Exercise:
Add a red color to all descendants of <ul>.
Hint
Hint: Use the find() method.
Edit This Code:
See Result »
<!DOCTYPE html> <html> <head> <style> .ancestors * { display: block; border: 2px solid lightgrey; color: lightgrey; padding: 5px; margin: 15px; } </style> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script> <script> $(document).ready(function(){ // add code here }); </script> </head> <body> <div class="ancestors"> <div style="width:500px;">div <ul>ul <li>li <span>span</span> </li> </ul> </div> </div> </body> </html>
Result:
Show Answer
Correct Code:
<!DOCTYPE html> <html> <head> <style> .ancestors * { display: block; border: 2px solid lightgrey; color: lightgrey; padding: 5px; margin: 15px; } </style> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script> <script> $(document).ready(function(){ $("ul").find("*").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>
Correct Result:
Hide Answer
Privacy Policy