jQuery :first-child 选择器 定义和用法 :first-child 选择器选择所有父元素的第一个子元素。 提示:使用 :last-child 选择器选择其父级的最后一个子元素。 语法 $(":first-child") 参数 参数 必需的 描述 该选择器没有任何参数 示例 下例演示了选择其父元素的第一个子元素的所有<p>元素背景设置为红色: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>欢迎来到菜鸟教程</title> //此版本是百度cdn 1.11.1,当然你可以使用更高的版本,从2.0版本以上的是不支持ie6-8的 <script type="text/javascript" src="http://libs.baidu.com/jquery/1.11.1/jquery.min.js"></script> <script> $(document).ready(function () { $("p:first-child").css("background","red"); }); </script> </head> <body> <p>段落1111</p> <div style="border:1px solid;"> <p>段落222</p> <p>段落222</p> </div> <br> <div style="border:1px solid;"> <span>span333</span> <p>段落333</p> <p>段落333</p> </div> </body> </html> 复制尝试一下 点击尝试一下,输出结果如下图所示: 相关页面 jQuery 选择器>>>>>> jQuery 实例>>>>>> 返回 jQuery 选择器参考