Javascript examples for jQuery Selector:last-child
The :last-child selector selects elements who are the last child of their parent.
The following code shows how to select every <p> element that is the last child of div parent:
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script> $(document).ready(function(){ $("div p:last-child").css("background-color", "red"); });//w ww. ja v a 2 s .co m </script> </head> <body> <p>The first paragraph in body.</p> <div style="border:1px solid;"> <p>The first paragraph in div.</p> <p>The last paragraph in div.</p> </div><br> <div style="border:1px solid;"> <p>The first paragraph in another div.</p> <p>E</p> </div> <p>A</p> </body> </html>