Javascript examples for jQuery:Tag Traversing
Add a red color to last <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").last().css("color", "red"); });// ww w.j a va 2 s .c om </script> </head> <body> <p>First paragraph.</p> <p>Second paragraph.</p> <p>Third paragraph.</p> <p>Last paragraph.</p> </body> </html>