GIF动态效果图:
代码部分:
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8"> <title></title> <script src="jquery-3.3.1.js"></script> </head> <body> <div> <p>我是第一个p元素</p> <p>我是第二个p元素</p> <p>我是第三个p元素</p> </div> <script type="text/javascript"> $(function(){ $("div").on("click",function(){ $(this).find("p:nth-child(2)").css("background","orange"); }); }); </script> </body> </html>