Home>Article>Web Front-end> Does jquery not support eq method?

Does jquery not support eq method?

WBOY
WBOY Original
2022-06-24 17:22:13 1340browse

jquery supports the eq method; this method can return the element with the specified index number of the selected element. The index number of the element starts from 0, and the syntax is "element object.eq(index)"; within the method The parameter is used to specify the index of the element, which can be set to an integer or a negative number. When the parameter is set to a negative number, the index will be calculated from the end of the selected element.

Does jquery not support eq method?

The operating environment of this tutorial: windows10 system, jquery3.6.0 version, Dell G3 computer.

jquery supports the eq method

The eq() method returns the element with the specified index number of the selected element.

Index numbers start with 0, so the index number of the first element is 0 (not 1).

Syntax

$(selector).eq(index)

Parameter Description

index Required. Specifies the index of the element. Can be an integer or negative number.

Note: Using negative numbers will calculate the index from the end of the selected element.

Example:

       
  • HTML
  • CSS
  • JavaScript
  • jQuery
  • Vue.js

The preview effect is as shown in the figure

Does jquery not support eq method?

The subscript of the eq() method starts from 0, and the The index of 1 li element is 0, the index of 2nd li element is 1,..., the index of nth element is n-1. Therefore, $("li").eq(3) means selecting the 4th li element.

$("li").eq(3).css("color", "red");

In fact, the eq() method is very similar to the :eq() selector. The above code can be equivalent to:

$("li:eq(3)").css("color", "red");

Friends will ask: "There is obviously an :eq() selector, why do we need to create an eq() method?" In fact, the form of the selector is fixed, and in some cases the effect will be poor, and filtering Methods allow us to manipulate elements more flexibly. In other words: the filtering method is actually a supplement to the selector

Video tutorial recommendation:jQuery video tutorial

The above is the detailed content of Does jquery not support eq method?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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