Javatpoint Logo
Javatpoint Logo

jQuery first() method

As its name implies, the first() method returns the first element of the selected elements. If we need to get the last element, we can use the last() method.

Syntax

This method doesn't accept any argument. The selector in the above syntax is mandatory to be specified.

Let's see some of the illustrations to understand how to use the first() method.

Example1

In this example, we are using the first() method to get the first paragraph element from the set of elements. We are using the p as the selector, so the method will return the first paragraph element.

Test it Now

Output

After the execution of the above code, the output will be -

jQuery first() method

After clicking the given button, the output will be -

jQuery first() method

Example2

In this example, we are using the first() method to get the first span element from the set of elements.

Test it Now

Output

After the execution of the above code, the output will be -

jQuery first() method

After clicking the given button, the output will be -

jQuery first() method




Youtube For Videos Join Our Youtube Channel: Join Now

Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA