jquery gets a summary of the methods of the first few elements

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.