This is the board drawing function
this.drawBoard=function(){
document.write('<table id="newGame">');
for(let i=0;i<boxes;i++){
document.write('<tr>');
for(let j=0;j<boxes;j++){
document.write(' <td id=" '+ i +' , '+ j + ' " ');
document.write('</td>');
}
document.write('</tr>');
}
document.write('</table>');
b.onClickEvent();
}
While this is the function to get the id
i found that by changing the 0
index in line clicked = cell.getElementsByTagName("td")[0].id;
I can get to the column I want but don't know how to manipulate it to get the exact cell id
this.onClickEvent=function() {
let table = document.getElementById("newGame");
let rows = table.getElementsByTagName("tr");
for (i = 0; i < rows.length; i++) {
let currentRow = table.rows[i];
var createClickHandler =
function(cell) {
return function() {
clicked = cell.getElementsByTagName("td")[0].id;
console.log(clicked);
let numbers=[];
clicked.replace(/(d[d.]*)/g, function( x ) { var n = Number(x); if (x == n) { numbers.push(x); } })
b.spliceGrid(numbers[0],numbers[1]);
numbers=[];
};
};
currentRow.onclick = createClickHandler(currentRow);
}
}
question from:
https://stackoverflow.com/questions/65838575/how-do-i-get-the-cell-id-of-a-table 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…