0
Pla help. JS - Can place a table element into a var by "getElelementById"? and if so what is the code to reach into an external
and if so what is the code to reach into an external html?
7 odpowiedzi
+ 1
Can you please explain your question better?
If what you want is to put a table into a variable, you can simply assign it to getElementById, every element can be assigned to a variable.
+ 1
If you want to change what is in a specific cell, you can use:
var cell35 = document.getElementById("board").rows[5].cells[3];
Then, if you want to put an image in the cell:
var cell = document.getElementById("board").rows[5].cells[3];
var img = document.createElement("img");
img.src = "image.png";
cell.appendChild(img);
Note that 3 and 5 are example numbers, that are 5 on the y and 3 on the x.
If all of this is a little vomplicated for you then I suggest you use a tutorial on a basic checkers game.
0
I made a checker board using a table and uni code. I want now to start programing the javascript in an external ".js" page while using the DOME.
-The table has an id "board".
And i started off by coding :
var t = document.getElementById("board").innerHTML;
but gives me an error.
How can i code it?
0
The error that it gives me is:
'document' is not defined.[no-undef]
0
This is the code
0
As you can see i just started learning...😬