How to use eq() Selector Method in JQuery

This article describe about :eq() Selector Method in JQuery.
  • 1888

Use :eq() Selector method in jQuery

This method is used to find a specific index number in a group.

In this method index number will be start at 0.

So the first element will have the index number 0 (not 1).

The :eq() method mostly use to another selector.

Example

<!DOCTYPE html>

<html>

<head>

<script type="text/javascript" src="jquery.js"></script>

<script type="text/javascript">

    $(document).ready(function () {

        $("p:eq(1)").css("background-color", "Yellow");

    });

</script>

</head>

<body>

<h1>This is JQuery</h1>

<p>Use :eq() Selector</p>

<p>I am Aman</p>

<p>Hello Wrold</p>

Who is your favorite:

<ul id="choose">

<li>My Self</li>

<li>My Friends</li>

</ul>

</body>

</html>

Output

op2.jpg

You may also want to read these related articles here

Ask Your Question 

Got a programming related question? You may want to post your question here

Programming Answers here

© 2020 DotNetHeaven. All rights reserved.