jQuery :first-childSelector

jQuery 选择器jQuery Selectors

Examples

Select the first <p> element in its parent:

$("p:first-child")

Try it Yourself »

Definition and Usage

The :first-child selector selects the first child element of its parent.

Tip:Please use:last-childselector to select the last child element of its parent.


Syntax

$(":first-child")


实例

Try it Yourself - Examples

Select the first <p> element of all <div> elements
How to select the first <p> element of all <div> elements.

The difference between :first and :first-child
Demonstrates the difference between the :first and :first-child selectors.

The difference between :first, :first-child, and :first-of-type
Demonstrates the difference between the :first, :first-child, and :first-of-type selectors.


jQuery 选择器jQuery Selectors

Other Extensions