Home >>jQuery Tutorial >jQuery :eq() Selector

jQuery :eq() Selector

jQuery :eq() Selector

jQuery :eq() selector in jQuery is used to selects an element with a specific index number which starts at 0.

Syntax:
$(":eq(index)")

Parameter Values

Parameter Description
index It is a Required parameter and used to specifies the index of the element
Here is an Example of jQuery :eq() Selector:

<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("p:eq(1)").css("background-color","orange");
});
</script>
</head>
<body>
<h1>Welcome to Phptpoint</h1>
<p class="intro">My name is phptpoint.</p>
<p>I live in Noida.</p>
<p>Who is your favourite:</p>
<ul id="fav">
<li>JAVA</li>
<li>jQuery</li>
<li>Javascript</li>
</ul>
</body>
</html>

Output:

Welcome to Phptpoint

My name is phptpoint.

I live in Noida.

Who is your favourite:

  • JAVA
  • jQuery
  • Javascript

No Sidebar ads