How to take corresponding row header and column header for a particular cell in table? I have table and I wanted to take the corresponding column header and row header of that cell when clicked.
You can use .index()
. To get the column use cell's index and to get the row, its row's index:
$('td').on('click', function() {
var row = $(this).closest('tr').index();
var col = $(this).index();
});
The returned numbers are zero-based so row=0 is the first row and col=0 the first column. Add 1 to them if you want to start from 1.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.