Example of using the eq () method in jQuery, jqueryeq
This document describes the usage of the eq () method in jQuery. Share it with you for your reference. The specific analysis is as follows:
This method can obtain the elements that match the index of the corresponding position on the element set.
The index that matches the element position in the element set starts from 0.
Syntax structure:
Copy codeThe Code is as follows: $ (selector). eq (index)
Parameter List:
| Parameters |
Description |
| Index |
Defines the index of an element in the element set, starting from scratch. If it is a negative number, Count back from the last element. Invalid. |
Instance code:
Instance 1:
Copy codeThe Code is as follows:
<! Doctype html>
<Html>
<Head>
<Meta charset = "UTF-8"/>
<Meta name = "author" content = "http://www.bkjia.com/"/>
<Title> eq () method-helping customers </title>
<Script type = "text/javascript" src = "mytest/jQuery/jquery-1.8.3.js"> </script>
<Script type = "text/javascript">
$ (Document). ready (function (){
$ ("Li" ).eq(1).css ("color", "blue ")
})
</Script>
</Head>
<Body>
<Div>
<Ul>
<Li> HTML zone </li>
<Li> Javascript area </li>
<Li> Div + Css area </li>
<Li> Jquery area </li>
</Ul>
</Div>
</Body>
</Html>
Set the font color in the li element with an index of 1 to blue.
Example 2:
Copy codeThe Code is as follows:
<! Doctype html>
<Html>
<Head>
<Meta charset = "UTF-8"/>
<Meta name = "author" content = "http://www.bkjia.com/"/>
<Title> click "effect" in the pop-up window to help customers </title>
<Style type = "text/css">
. Font {
Font-size: 18px;
Color: yellow
}
. Bg {
Background: #336;
}
</Style>
<Script type = "text/javascript" src = "mytest/jQuery/jquery-1.8.3.js"> </script>
<Script type = "text/javascript">
$ (Document). ready (function (){
$ ("Li" ).eq(-1).css ("color", "blue ")
})
</Script>
</Head>
<Body>
<Div>
<Ul>
<Li> HTML zone </li>
<Li> Javascript area </li>
<Li> Div + Css area </li>
<Li> Jquery area </li>
</Ul>
</Div>
</Body>
</Html>
When the index is a negative number, Count back from the last element.
I hope this article will help you with jQuery programming.