The difference and use of the EQ and get for jquery objects in jquery--the tool to operate the foreground display

Source: Internet
Author: User

: the EQ () selector selects the element with the specified index value.

The index value starts at 0, and the index value of all first elements is 0 (not 1).


Get (Index) gets one of the matching elements. The index represents the element that gets the first few matches.

This allows you to select an actual DOM element and manipulate it directly, rather than through the JQuery function. $ (this). Get (0) is equivalent to $ (this) [0].


Here's a simple code to illustrate the following:

<script type= "Text/javascript" src= "Http://u.myxzy.com/jquery/jquery-1.7.1.js" ></script> <script > $ ("Document"). Ready (function () {        alert ($ ("Li:eq (0)");       Alert ($ ("Li"). Get (0));}) </script> <ul>  <li>Li-1</li>  <li>Li-2</li></ul>

The result is

The returned results were: [Object Object] and [object Htmllielement]

It is known that EQ returns a JQuery object, and get returns an array of HTML objects.


Use EQ to get the color value of the first Li tag:

$ ("li"). EQ (0). CSS ("color")//Because EQ (num) Returns a JQ object, you can use the JQ method css

Use get to get the color value of the second Li tag:

$ ("Li"). Get (1). Style.color//Because get (num) returns an HTML object, the JQ object is useless at this point, using the traditional HTML object method.


Of course, you can also get (num) The object to the JQ object and then manipulate it:

$ ($ ("Li"). Get (1)). CSS ("color")


So we know that the jquery object returned by EQ, we can directly use jquery methods such as. css (),. html (), and so on, and the get returned is an HTML array object to use the traditional HTML object method or converted to a JQuery object before operation.

Note: You can achieve the same effect, so it is recommended to use the EQ in a unified way, without having to bother about the difference between them.


<script type= "Text/javascript" src= "Http://u.myxzy.com/jquery/jquery-1.7.1.js" ></script><script >$ ("document"). Ready (function () {$ ("Li:eq (0)"). CSS ("Color", ' Red '), $ ("Li"). EQ (1). CSS ("Color", ' Blue '); $ ("Li"). Get (2). style.color= ' green '; $ ($ ("Li"). Get (3)). CSS ("color", ' yellow ');}) </script><ul><li>li-1</li><li>li-2</li><li>li-3</li><li> Li-4</li></ul>


The difference and use of the EQ and get for jquery objects in jquery--the tool to operate the foreground display

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.