:first-child

本页内容
上一节: Sel_odd 下一节: Sel_firstoftype

jQuery :first-child 选择器

jQuery 选择器

选取属于 <p> 的父元素中第一个为 <p> 的元素:


示例

$("p:first-child")

定义和用法

first-child 选择器选取属于其父元素的第一个子元素。

提示:请使用 :last-child 选择器来选取属于其父元素的最后一个子元素。

语法

$(":first-child")

尝试一下 - 实例

选取所有 <div> 元素的第一个 <p> 元素 如何选取所有 <div> 元素的第一个 <p> 元素。

:first 和 :first-child 之间的不同 演示 :first 和 :first-child 选择器之间的不同。

:first、:first-child 和 :first-of-type 之间的不同 演示 :first、:first-child 和 :first-of-type 选择器之间的不同。

jQuery 选择器

上一节: Sel_odd 下一节: Sel_firstoftype
此页面最后编辑于2022年8月19日 (星期五) 11:37。