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 get the row and column of the current element by jquery

2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

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!

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