Home
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script> <script> $(document).ready(function () { $("button").click(function () { $('div p').last().css("background-color", "yellow"); $('li').last().css("background-color", "yellow"); $('p').last().css("background-color", "yellow"); }); }); </script> </head> <body> <h1>jQuery DOM Traversing Methods: last()</h1> <div id="myDiv"> <p>Paragraph 1</p> <p>Paragraph 2</p> <p>Paragraph 3</p> <p>Paragraph 4</p> </div> <ul> <li>List 1</li> <li>List 2</li> <li>List 3</li> <li>List 4</li> </ul> <p>Paragraph 5</p> <button>Click Here to Test .last()</button> </body> </html>
Result: