Home >>jQuery Tutorial >jQuery :first Selector

jQuery :first Selector

jQuery :first Selector

jQuery :first selector in jQuery is used to selects one single element. To select more than one element (one for each parent) you can use the :first-child selector.

Syntax:
$(":first")
Here is an Example of jQuery :first Selector:

<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("p:first").css("background-color", "orange");
});
</script>
</head>
<body>
<p>This is the first paragraph.</p>
<p>This is the second paragraph.</p>
<p>This is the Third paragraph.</p>
</body>
</html>

Output:

This is the first paragraph.

This is the second paragraph.

This is the Third paragraph.