jQuery first()Method

jQuery 遍历方法jQuery Traversal Methods

Example

Select the first <p> element inside the first <div> element:

$("div p").first()

Try it Yourself »

Definition and Usage

The first() method returns the first element of the selected elements.

Tip:To return the last element, use thelast()method.


Syntax

$(selector).first()


实例

More Examples

Select the first <span> element in the collection of <p> elements
How to select the first <span> element within a set of <p> elements.


jQuery 遍历方法jQuery Traversal Methods

Other Extensions