Home Web Front-end JS Tutorial The difference and usage between eq and get in jquery_jquery

The difference and usage between eq and get in jquery_jquery

May 16, 2016 pm 06:07 PM
eq get

For example:

Feiyu

Use eq to get the color value of the first p tag:
$("p").eq (0).css("color") //Because eq(num) returns a jq object, you can use the jq method css to use get to get the color value of the first p tag:
$("p ").get(0).style.color //Because get(num) returns an html object, the traditional HTML object method must be used, and the jq object is useless at this time. Of course, you can also get(num) and convert the object to a jq object before performing the operation:
$($("p").get(0)).css("color")----- -------------------------------------------------- ------------------
more eq
see:
http://api.jquery.com/eq/
--- -------------------------------------------------- ---------------------
more get:
see:
http://api.jquery.com/get/
eq: The return is a jquery object whose function is to reduce the set of matched elements to one element. The position of this element in the set of matching elements becomes 0, and the length of the set becomes 1
get: is an array of html objects that is used to obtain one of the matching elements. num indicates which matching element is obtained.

For example: html code

Copy code The code is as follows:

< ul>
  • li-1

  • li-2



  • For example, we pass jquery selector $("li") Then we will have two li elements. How can I only select one of them?

    $("li:eq(0)").html() or $ ("li").eq(0).html() is the first li. Here we will get li-1
    $("li:eq(1)").html() or $("li" ).eq(1).html() is the second li. Here we will get li-2

    Let’s look at get. Because get returns an html object, here we are
    $("li" ).get(0).style.color='red'
    Only used in this way or convert the object returned by get into a jquery object before operating
    $($("li").get(0)).css ("color",'red') can

    Complete code
    Copy code The code is as follows:












    • li-2




    Statement of this Website
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

    Hot AI Tools

    Undresser.AI Undress

    Undresser.AI Undress

    AI-powered app for creating realistic nude photos

    AI Clothes Remover

    AI Clothes Remover

    Online AI tool for removing clothes from photos.

    Undress AI Tool

    Undress AI Tool

    Undress images for free

    Clothoff.io

    Clothoff.io

    AI clothes remover

    Video Face Swap

    Video Face Swap

    Swap faces in any video effortlessly with our completely free AI face swap tool!

    Hot Tools

    Notepad++7.3.1

    Notepad++7.3.1

    Easy-to-use and free code editor

    SublimeText3 Chinese version

    SublimeText3 Chinese version

    Chinese version, very easy to use

    Zend Studio 13.0.1

    Zend Studio 13.0.1

    Powerful PHP integrated development environment

    Dreamweaver CS6

    Dreamweaver CS6

    Visual web development tools

    SublimeText3 Mac version

    SublimeText3 Mac version

    God-level code editing software (SublimeText3)

    How to automate tasks using PowerShell How to automate tasks using PowerShell Feb 20, 2024 pm 01:51 PM

    If you are an IT administrator or technology expert, you must be aware of the importance of automation. Especially for Windows users, Microsoft PowerShell is one of the best automation tools. Microsoft offers a variety of tools for your automation needs, without the need to install third-party applications. This guide will detail how to leverage PowerShell to automate tasks. What is a PowerShell script? If you have experience using PowerShell, you may have used commands to configure your operating system. A script is a collection of these commands in a .ps1 file. .ps1 files contain scripts executed by PowerShell, such as basic Get-Help

    How does java initiate an http request and call the post and get interfaces? How does java initiate an http request and call the post and get interfaces? May 16, 2023 pm 07:53 PM

    1. Java calls post interface 1. Use URLConnection or HttpURLConnection that comes with java. There is no need to download other jar packages. Call URLConnection. If the interface response code is modified by the server, the return message cannot be received. It can only be received when the response code is correct. to return publicstaticStringsendPost(Stringurl,Stringparam){OutputStreamWriterout=null;BufferedReaderin=null;StringBuilderresult=newSt

    Understand the role and application scenarios of eq in jQuery Understand the role and application scenarios of eq in jQuery Feb 28, 2024 pm 01:15 PM

    jQuery is a popular JavaScript library that is widely used to handle DOM manipulation and event handling in web pages. In jQuery, the eq() method is used to select elements at a specified index position. The specific usage and application scenarios are as follows. In jQuery, the eq() method selects the element at a specified index position. Index positions start counting from 0, i.e. the index of the first element is 0, the index of the second element is 1, and so on. The syntax of the eq() method is as follows: $("s

    Example of Curl Get command Example of Curl Get command Mar 20, 2024 pm 06:56 PM

    In Linux, URL or Curl client is a popular command line utility that allows you to transfer data over the network using various protocols such as HTTPS, HTTP, FTP, etc. It allows you to send and receive data using its get, post and request methods. Among them, you need to use the &quot;get&quot; method frequently. Therefore, it becomes crucial to learn various methods and various options that you can use to increase your productivity. &quot;Performing a curl operation is as simple as entering a few simple commands. Although it seems simple, many users do not fully realize its potential. Therefore, this short guide provides some information on how to perform curl operations on Linux systems. Example using the &quot;curlget&quot; command.&quot; Curl

    What does linux eq mean? What does linux eq mean? Mar 23, 2023 am 09:43 AM

    linux eq means "equal to" and is a comparison operator in Linux, used to determine whether the numerical values ​​corresponding to strings are equal; the method of using this operator is such as "if [ $num1 -eq $num2 ] then echo "$num1 and $num2xiangdeng" else echo "$num1 and $num2buxiangdeng"".

    How to change Ubuntu's apt-get update source? How to change Ubuntu's apt-get update source? Jan 05, 2024 pm 03:40 PM

    Manually modify Ubuntu's apt-get source 1. Use the ssh tool to connect to Ubuntu (I use xshell) 2. Type cd/etc/apt/3 on the command line and back up the source.list file in this directory (you must have sudo permissions) ), then there is a source.list.bak file. 4. Clear the source.list file content (note: it cannot be restored after clearing, so you need to perform the previous step to back up the file in advance). At this time, use sudo to prompt that the permissions are insufficient. Switch directly to the root user and execute this command. 5. Use vim to open source.list, press the i key to enter the editing mode, paste the source address to be modified, and then press

    How does SpringBoot use entities to receive multiple parameters passed by the Get request? How does SpringBoot use entities to receive multiple parameters passed by the Get request? May 19, 2023 pm 06:01 PM

    1. The first method of the Controller layer receiving parameters without any annotations is the simplest. I seriously doubt why it was not used before. Who knows. . But this time it really worked. The simplest way is to add the Controller interface without adding any annotations! ! ! SpringBoot handles this automatically. The code is as follows: /***@authorzhangzhixiang*@sincev1.0.0*/@RestController@RequestMapping(path="/ui/institution")publicclassInstitutionManagemen

    In-depth analysis of the similarities and differences between the get method and post method in jQuery In-depth analysis of the similarities and differences between the get method and post method in jQuery Feb 24, 2024 pm 12:15 PM

    Get and post are two commonly used ajax request methods in jQuery, which are used to send requests to the server and obtain data. They have some differences in usage and some features. Next we will explain their similarities and differences in detail, and attach specific code examples. The similarities between get and post: they are both methods for sending ajax requests. You can obtain data from the server by specifying the URL and data parameters. Both can accept callback functions as parameters, which are used to process data returned by the server or handle failed requests.

    See all articles