Jquery is often used. After selecting a group of elements, you need to find the first element in this group.
In jquery, the eq () method is used to locate the nth element or the nth element. The usage of eq () in jquery is as follows:
The eq () selector selects an element with the specified index value.
The index value starts from 0, and the index value of all the first element is 0 (not 1 ).
It is often used with other elements/selectors to select the element with a specific sequence number in the specified group.
Example:
| The code is as follows: |
Copy code |
Certificate ('{test'}.children().eq(1).css ({'display': 'inline-block '}); |
Set the second child element style of the element whose id is test to 'display': 'inline-block '.
Another method
| The code is as follows: |
Copy code |
$ (": Eq (index )") For example: $ ("p: eq (1 )") |
Example of another method
| The code is as follows: |
Copy code |
<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 it like this.
| The code is as follows: |
Copy code |
<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.