Prev Demo
jQuery
>
First-Child - First 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>First 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 first child in the #div2 is selected</p> <script language="javascript" type="text/javascript"> $("#div2 p:first-child").css("background", "red"); </script> </body> </html>
Note: We DO NOT save your trial code in our database.
Output