How does jquery query which tr the current element is?
The main content of this article is to explain "jquery how to query the current element is which tr", interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Next let the editor to take you to learn "jquery how to query the current element is which tr" it!
Methods: 1, use the "$(this)" statement and index () method to obtain the index position of the current tr element, and then get the number of the current element, the syntax is "$(this). Index () + 1;"; 2, use the alert () method to output the number of current element positions.
The operating environment of this tutorial: windows10 system, jquery3.2.1 version, Dell G3 computer.
How does jquery query which tr the current element is?
We can query the number of tr of the current element through the index () method.
The index () method returns the index position of the specified element relative to other specified elements.
These elements can be specified through jQuery selectors or DOM elements.
Note: if no element is found, index () returns-1.
Examples are as follows:
$(function () {("table tr") .click (function () {var col = $(this). Index () + 1; / column location alert ("current location: + col+" tr ")});}); 1234 2456 3789 4123
Output result:
When you click on the second line of elements, output the result:
At this point, I believe you have a deeper understanding of "jquery how to query the current element is the number of tr", might as well to the actual operation of it! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!