0

Please tell me what is wrong in my code whenever i am clicking on the center button it shows [not defined].plz help

https://code.sololearn.com/W8KOUOGB80fE/?ref=app

23rd Jun 2020, 5:55 AM
Aditya sahani
Aditya sahani - avatar
2 odpowiedzi
+ 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
23rd Jun 2020, 6:14 AM
KrOW
KrOW - avatar
+ 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.
23rd Jun 2020, 8:23 AM
ChaoticDawg
ChaoticDawg - avatar