I would like to create table with javascript. I would like to ask user, for width and height of a table (1 cell is 1 unit). Then when table is created, if user clicks in to one of the cell, color changes. I have so code written, but I am pretty much stuck.
HTML CODE:
<script src="script.js"></script>
<style>
#chessboard{border: 1px solid black; border-collapse: collapse}
td {width: 40px; height: 40px}
tr:nth-child(odd) td:nth-child(even) {background: black}
tr:nth-child(even) td:nth-child(odd) {background: black}
</style>
</head>
<body onload="myFunction()">
<div>
<table id="chessboard">
</table>
</div>
</body>
JAVASCRIPT:
var width = parseInt(prompt("Put width", "here"));
var height = parseInt(prompt("Put height", "here"));
function myFunction()
{
var tabel = document.getElementById("chessboard");
for (i = 0; i < height; i++){
var row = tabel.insertRow(i);
};
for (j = 0; j < width; j++){
var celica = document.getElementByTagName("tr").rows[j];
var x = celica.insertCell(j);
};
}