jQuery :firstSelector

jQuery 选择器jQuery Selectors

Examples

Select the first <p> element:

$("p:first")

Try it »

Definition and Usage

The :first selector selects the first element.

Note:This selector is only used to select a single element. Use:first-childthe selector to select multiple elements (one for each parent).

Most common usage: Used together with other selectors to select the first element in a specified combination (like the example above).

Tip:To select the last element in a specified combination, use:lastthe selector.


Syntax

$(":first")


实例

Try it - Examples

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


jQuery 选择器jQuery Selectors

Other Extensions