0
Please tell me what is wrong in my code whenever i am clicking on the center button it shows [not defined].plz help
2 Answers
+ 2
Browser add inside table a tbody tag then ehen you get child of table you will get tbody and not tr tags, then try to select #table tbody. Futhermore, use children and not childNodes
+ 2
Since you're using jQuery you can do this;
function add(x,y) {
if(x==1 && y==1) {
let td = $("#table tr").get(x).children[y];
$(td).text("X");
}
}
Without jquery
function add(x,y) {
if(x==1 && y==1) {
let table = document.getElementById("table");
let td = table.rows[x].children[y];
td.innerHTML = "X";
}
}
Either way you'll need to use only onclick="add(x, y)" as using the click() function with it will cause issues if both are accessing and changing the same element. If you need for some reason to use both, keep in mind that the onclick="add(x, y)" runs then the .click() function.