Prev Demo
jQuery
>
Last-Child - Last Child Selector
Next Demo
Write code here
J
|
B
|
A
<!DOCTYPE html> <html> <head> <title>Demo</title> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script> </head> <body> <h1>Last child selector.</h1> <h3>Children in #div1</h3> <div id="div1"> <p>Ravi</p> <p>Raju</p> <p>Ranga</p> </div> <hr /> <h3>Children in #div2</h3> <div id="div2"> <p>Sasi</p> <p>Sadi</p> <p>Salomi</p> </div> <br /> <br /> <p>Hence Last child in the #div2 is selected</p> <script language="javascript" type="text/javascript"> $("#div2 p:last-child").css("background", "red"); </script> </body> </html>
Note: We DO NOT save your trial code in our database.
Output