I'm trying to get a TD ID when I'm clicking on a table's row.
I've searched for ways to realize this, and found a way. But everytime I'm clicking, an alert pops up but it's an empty text. Using the console I saw that's the error code is "undefined".
Here's my code :
function chooseCell() {
let square = 0;
let squareNumber = 0;
$("td").click((e) => {
let data = $(this).attr('id');
alert (data);
for (square in squarePositions) {
squareNumber += 1;
if (square[1] <= e.pageX <= square[3] && square[0] <= e.pageY <= square[2]) {
alert(squareNumber);
alert("Square Number : " + squareNumber);
}
}
}
)}
If I replace the alert(data) by :
alert($('td').attr('id'));
The alert pops up the first table's TD. Whenever I click on a different TD, the first ID is displayed
Does someone know how to display the current clicked id ? There were no answers for my problem on Google and SOF
Thank you very much, best regards.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…