JQuery first()
The first()
method in JQuery allows you to select the first element in a set of matched elements.
Syntax
The syntax for first()
is as follows:
$(selector).first();
selector
: the element(s) to be selected
Use
The first()
method is often used when you want to select only the first element of a group of elements. For example, if you have a list of items and you want to highlight only the first item, you can use the first()
method to select it.
Example
Here is an example of using first()
method in JQuery: