Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use eq () of jquery

2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces "how to use eq () of jquery". In daily operation, I believe many people have doubts about how to use eq () of jquery. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts of "how to use eq () of jquery"! Next, please follow the editor to study!

In jquery, the eq () method is used to return the element with the specified index number of the selected element, the syntax "$(selector) .eq (index)", while the ": eq ()" selector is used to select the element with the specified index value, and the syntax "$(": eq (index) ")".

The operating environment of this tutorial: windows7 system, jquery1.10.2 version, Dell G3 computer.

In jquery, eq () is divided into two situations:

Eq () method

Eq () selector

Jquery eq () method

The eq () method returns the element with the specified index number of the selected element. The index number starts with 0, so the index number of the first element is 0 (not 1).

Syntax:

$(selector) .eq (index)

Index: required. Specifies the index of the element, which can be integer or negative. If you use a negative number, the index is calculated starting at the end of the selected element.

Note: the index number (index) starts at 0, so the index number of the first element is 0 (not 1).

Example 1: select the second

Element (index number is 1)

$(document) .ready (function () {$("p"). Eq (1). Css ("background-color", "yellow");}); Welcome to my home page

My name is Donald (subscript 0).

Donald Duck (index 1).

I live in Duckburg (index 2).

My best friend is Mickey (index 3).

Example 2: use a negative number to return the second from the end of the selected element

element.

$(document) .ready (function () {$("p"). Eq (- 2). Css ("background-color", "yellow");}); Welcome to my home page

My name is Donald.

Donald Duck .

I live in Duckburg (will be selected because it is the penultimate element).

My best friend is Mickey.

Jquery: eq () selector

The eq () selector selects the element with the specified index value.

The index value starts at 0, so the index value of the first element is 0 (not 1).

The most common usage: use with other selectors to select the elements of the specified index in the specified combination.

Syntax:

$(": eq (index)")

Index: required. Specifies the index of the element.

Example: select the second

Elements:

$(document) .ready (function () {$("p:eq (1)") .css ("background-color", "yellow");}); Welcome to my home page

My name is Donald.

Donald Duck .

I live in Duckburg.

My best friend is Mickey.

At this point, the study of "how to use eq () of jquery" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report