Home > Web Front-end > JS Tutorial > How to determine which element the current element is in jquery

How to determine which element the current element is in jquery

藏色散人
Release: 2021-11-12 10:10:43
Original
3849 people have browsed it

How jquery determines which element the current element is: 1. Create an HTML sample file; 2. Use the jQuery code "$("ul li").click(function () {var index = $( "ul li").index...})" can be used to judge.

How to determine which element the current element is in jquery

The operating environment of this article: windows7 system, jquery version 3.2.1, DELL G3 computer

How does jquery determine the order of the current element? indivual?

Suppose there is the following HTML code:

<ul>
    <li>jQuery判断当前元素是第几个元素示例</li>
    <li>jQuery获取第N个元素示例</li>
    <li>jQuery选择器示例</li>
</ul>
Copy after login

jQuery determines which element the current element is

If we click on any li tag, we want to know the current To determine which li tag is clicked, you can use the following code:

$("ul li").click(function () {
    var index = $("ul li").index(this);
    alert(index);
 });
Copy after login

Such as the jQuery code above, if the first one is clicked, "0" will be prompted, if it is the second Each li tag will prompt "1". Note that the index sequence number starts from 0.

Recommended learning: "jquery video tutorial"

The above is the detailed content of How to determine which element the current element is in jquery. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template