I was thinking if there’s a better solution for adding onclick handler to each cell in a table than this approach: Adding an onclick event to a table row
Better in the way that I wouldn’t need to set “cell.onclick = function” for each cell.
I just need to get the coordinations of a cell where user clicked.
Thanks!
EDIT: The “coordinations” mean 0x0 for top-left cell, 0x1 for second cell in the first row etc.
Are you looking for this?
In case your table cells are generated dynamically:
.
Update Based On OP Comment:
To get
topandleftvalues you could try this:As your other comment shows, you are probably looking to get the IDs of the clicked cell, you may try this:
But for the above to work, it is assumed that all cells already have an
idattribute.