Home >>jQuery Tutorial >jQuery eq() Method

jQuery eq() Method

jQuery eq() Method

jQuery eq() methodin jQuery is used to returns an element with a specific index number 0 (not 1) of the selected elements.

Syntax:
$(selector).eq(index)

Parameter Values

Parameter Description
index It is a Required parameter and is used to specifies the index of the element, it can be either be a positive or negative number.
Here is an Example of jQuery eq() Method:

<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$(".txt1").eq(1).css("background-color", "#df65f7");
});
</script>
</head>
<body>
<h1>Welcome to Phptpoint</h1>
<p class="txt1">This is First Paragraph</p>
<p class="txt1">This is Second Paragraph</p>
<p class="txt1">This is Third Paragraph</p>
<p class="txt1">This is Fourth Paragraph</p>
</body>
</html>

Output:

Welcome to Phptpoint

This is First Paragraph

This is Second Paragraph

This is Third Paragraph

This is Fourth Paragraph