Get the App
SLTechnology News&Howtos  ›  Development  › 

How to get the row and column of the current element by jquery

Shulou Source: shulou.com Published: 2022-06-02 09:18:42 09月14日 Update

This article introduces the relevant knowledge of "how to obtain the current elements in which rows and columns". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Methods: 1, use the index () and parent () methods to get the row position of the current element, the syntax is "element object .parent (). Index () + 1;"; 2, use the index () method to get the column position of the current element, the syntax is "element object .index () + 1;".

The operating environment of this tutorial: windows7 system, jquery3.2.1 version, Dell G3 computer.

How to get the row and column of the current element by jquery

We can use the index () method and the parent () method to get the row and column of the current element, as shown in the following example:

1234 2456 3789 4123 $(function () {("table td") .click (function () {var row = $(this). Parent (). Index () + 1; / Row position var col = $(this). Index () + 1; / / column location alert ("current position: line" + row+ "," column "+ col+")});})

Output result:

When you click on one of the cell elements, output the result:

This is the end of the content of "how to get the current element in which row and column" by jquery. Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Tags: Element location method output content object more knowledge result grammar utility achievement next unit can pass dilemma actual situation tutorial article Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei MariaDB MySQL Xiaomi Redmi