When you use jquery, you often experience that when a selector selects a set of elements, it needs to find the first few elements in the set of elements.
In jquery, the EQ () method is used to find the first few elements or nth elements, using the following in jquery (eq):
The EQ () selector selects the element with the specified index value.
The index value starts at 0, and the index value of all the first elements is 0 (not 1).
Often used with other elements/selectors to select elements of a specific ordinal in a specified group.
Example:
| The code is as follows |
|
$ (' #test '). Children (). EQ (1). css ({' Display ': ' Inline-block '}); |
Set the second child element style for the element with ID test to ' Display ': ' Inline-block '.
Another way of writing
| The code is as follows |
|
$ (": EQ (Index)") such as: $ ("P:eq (1)") |
An example of another approach
| The code is as follows |
|
<script type= "Text/javascript" src= "/jquery-latest.js" ></script> <script> $ (function () { $ (' a '). each (function (i) { This.onclick=function () { alert (i); return false; }; }); }); </script> <a href= "" > Baidu </a> <a href= "" >google</a> <a href= "Http://www.111cn.net" >msn</a> <a href= "" >qq</a> |
or write that.
| The code is as follows |
|
<script type= "Text/javascript" src= "Jquery-1.1.3.1.js" ></script> <script type= "Text/javascript" > $ (function () { $ ("a"). Bind ("click", Function () { Alert ($ ("a"). Index (this)); } ) } ) </script> |
The effect is the same OH.