Prev Demo
jQuery
>
Nth-Child(N) - Nth Child
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> <h3>Children in #div1</h3> <div id="div1"> <p>Ranga</p> <p>Ramu</p> <p>Rehman</p> <p>Rajesh</p> </div> <hr /> <h3>Children in #div2</h3> <div id="div2"> <p>Srrayvinya</p> <p>Charitha</p> <p>Sharmila</p> <p>Sasikala</p> </div> <br /> <p>Hence nthchild(2) in the #div2 is selected</p> <script language="javascript" type="text/javascript"> $("#div2 p:nth-child(2)").css("background", "red"); </script> </body> </html>
Note: We DO NOT save your trial code in our database.
Output