I have a snippet of code that draws a table 10 rows by 10 columns then calls it “thisTable”.
Now looking to use JS to give an id to a particular td in the table, but not having any joy so far.
Thought this would work
var tbl = document.getElementById("thisTable");
tbl.rows[2].cells.item(2).setAttribute("name","thiscell");
But no joy. No doubt something simple wrong but can’t see it. TIA
Your code is setting the attribute name
instead of id
.
Oh FFS. Of course. Thanks.
Having changed it though I’m getting “Uncaught TypeError: tbl.getElementById is not a function”. Why would that be?
Got it! Should be document.getElementById and not the table. In case anyone else stumbles across this.
Good job figuring it out! Happy coding.
system
Closed
6
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.