Exercise:
Add a red color to all <p> elements with class="intro".
Hint
Hint: Use the filter() method.
Edit This Code:
See Result »
<!DOCTYPE html> <html> <head> <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> <p>First paragraph.</p> <p class="intro">Second paragraph.</p> <p class="intro">Third paragraph.</p> <p>Last paragraph.</p> </body> </html>
Result:
Show Answer
Correct Code:
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script> <script> $(document).ready(function(){ $("p").filter(".intro").css("color", "red"); }); </script> </head> <body> <p>First paragraph.</p> <p class="intro">Second paragraph.</p> <p class="intro">Third paragraph.</p> <p>Last paragraph.</p> </body> </html>
Correct Result:
Hide Answer
Privacy Policy