I am trying to make it so when you click on one of the <td>
s in the table, the SVG will appear in it.
This is a version of my code with four slots instead of 64, but the functions are the same:
function addPiece() {
document.getElementsByName("square").innerHTML = document.write("<svg width='100' height='100'> <circle cx='50' cy='50', r='40' stroke='black' stroke-width='4' fill='white' /> </svg>");
}
.square {
background-color: #459f60;
width: 100px;
height: 100px;
}
<table style="border: 2px solid #808080">
<tr>
<td class="square" name="square" id="0-0" onclick="addPiece()"></td>
<td class="square" name="square" id="0-1" onclick="addPiece()"></td>
</tr>
<tr>
<td class="square" name="square" id="1-0" onclick="addPiece()"></td>
<td class="square" name="square" id="1-1" onclick="addPiece()"></td>
</tr>
</table>
The problem with this code is that it just replaces the whole thing with the SVG instead of inputting it inside the <td>
that was clicked.
It will be very appreciated to get some help here as I'm really low level in js and html.