English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

jQuery first() Method

jQuery Traversal Methods

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

To return the last element, uselast()Method.

Syntax:

$.first(selector)

Example

Highlight the first paragraph:

$("document").ready(function(){
  $("p").first().css("background", "coral");
});
Test See‹/›

Highlight the first paragraph within the first DIV element:

$("document").ready(function(){
  $("div p").first().css("background", "coral");
});
Test See‹/›

Highlight the first unordered list:

$("document").ready(function(){
  $("ul").first().css("background", "coral");
});
Test See‹/›

jQuery Traversal Methods