Javascript examples for jQuery:Tag Traversing
Add a red color to first <p> element.
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script> $(document).ready(function(){ $("p").first().css("color", "red"); });// www. j ava 2 s .c o m </script> </head> <body> <p>First paragraph.</p> <p>Second paragraph.</p> <p>Third paragraph.</p> <p>Last paragraph.</p> </body> </html>