Example of using the eq () method in jQuery, jqueryeq

Source: Internet
Author: User

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.

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.