Table of Contents
What is EQ in jQuery?
In simple Terms from a larger set of elements, EQ in jQuery helps you to select or locate the particular element and returns an element with a specific index number. Now you can change the attributes of that element like color, size etc.
Please Note:
Index numbers start at 0, so the first element will have the index number 0 and not 1.
EQ value can be positive or negative and Using a negative number will start the index count from the end of the selected elements, instead of the beginning.
lets discuss with examples for more clarification
EQ in jQuery Properties
- The index numbers start at 0, so the first element will have the index number 0 and not 1.This will become more clear with the below example. Download jQuery script file from here.
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<script src="jquery-3.4.1.js"></script>
</head>
<body>
<ul>
<li>This is line 1</li>
<li>This is line 2</li>
<li>This is line 3</li>
<li>This is line 4</li>
<li>This is line 5</li>
<li>This is line 6</li>
</ul>
<script>
$(document).ready(function(){
$("li").eq(0).css("background-color","yellow");
})
</script>
</body>
</html>

Here to change the background color of line 1, we write eq value 0 as the first element will have the index number 0. Similarly to select line 4 we set the eq value to 3.
2. Using a negative number will start the index count from the end of the selected elements, instead of the beginning. This will become more clear with the below example.
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<script src="jquery-3.4.1.js"></script>
</head>
<body>
<ul>
<li>This is line 1</li>
<li>This is line 2</li>
<li>This is line 3</li>
<li>This is line 4</li>
<li>This is line 5</li>
<li>This is line 6</li>
</ul>
<script>
$(document).ready(function(){
$("li").eq(-1).css("background-color","yellow");
})
</script>
</body>
</html>

If we set eq value to -1 than the last line i.e. line 6 will select. So eq value can be positive or negative.
Frequently Asked Questions
why we use eq in jquery?
EQ helps us to select a particular element from various elements.
What does EQ mean in jQuery?
EQ is one of the jQuery transversing method which helps to select an element from various elements.
For more visit software schooling.