Skip to content Skip to sidebar Skip to footer

How To Obtain Row And Column Information Of A Clicked Table

I have the following fiddle - where I am testing out a concept of getting to the data in a table. At the moment, I can get to the value displayed in a particular cell, when i click

Solution 1:

Insead of adding onclick event to each cell you can add it to table, and get neccesary info from argument:

var tbl = document.getElementById("recordingTable");
tbl.onclick = function(e)
{
    console.log(e.target.innerHTML);
    console.log(e.target.cellIndex);
    console.log(e.target.parentElement.rowIndex);
}

JsFiddle: https://jsfiddle.net/19qfsxr9/14/

Solution 2:

You can get by using

cel.rowIndex
cel.cellIndex

in the function

Post a Comment for "How To Obtain Row And Column Information Of A Clicked Table"