小白教程
所有教程
关于
Search
172.70.130.171
172.70.130.171
参数设置
贡献
退出
操作
编辑
移动
保护
信息
历史
删除
查看“Jq sel firstchild”的源代码
本页内容
上一节:
Sel_odd
下一节:
Sel_firstoftype
因为以下原因,您没有权限编辑本页:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
{{DISPLAYTITLE::first-child}}[[Category:jquery ref selectors|11]] = jQuery :first-child 选择器 = [[jquery ref selectors|jQuery 选择器]] 选取属于 <p> 的父元素中第一个为 <p> 的元素: <sample title="" desc="" lang="html" hererun="1"> $("p:first-child") </sample> <run name=""> <!DOCTYPE html> <html> <head> <script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"> </script> <script> $(document).ready(function(){ $("p:first-child").css("background-color","yellow"); }); </script> </head> <body> <p>The first paragraph in body.</p> <div style="border:1px solid;"> <p>The first paragraph in div.</p> <p>The last paragraph in div.</p> </div><br> <div style="border:1px solid;"> <span>This is a span element.</span> <p>The first paragraph in another div.</p> <p>The last paragraph in another div.</p> </div> <p>The last paragraph in body.</p> </body> </html> </run> == 定义和用法 == :first-child 选择器选取属于其父元素的第一个子元素。 '''提示:'''请使用 [[sel lastchild|:last-child]] 选择器来选取属于其父元素的最后一个子元素。 == 语法 == $(":first-child") == 尝试一下 - 实例 == [[try.php?filename=tryjquery_sel_firstchild2|选取所有 <div> 元素的第一个 <p> 元素]] 如何选取所有 <div> 元素的第一个 <p> 元素。 [[try.php?filename=tryjquery_sel_firstchild_first|:first 和 :first-child 之间的不同]] 演示 :first 和 :first-child 选择器之间的不同。 [[try.php?filename=tryjquery_sel_firstoftypediff|:first、:first-child 和 :first-of-type 之间的不同]] 演示 :first、:first-child 和 :first-of-type 选择器之间的不同。 [[jquery ref selectors|jQuery 选择器]]
返回至“
Jq sel firstchild
”。
上一节:
Sel_odd
下一节:
Sel_firstoftype