I have a problem generating a table by JavaScript, in the code that I show below, the rows are generated on the right instead of continuing below to follow the column, the first column and the first row have to have & lt ; 'th' > as a requirement and the other cells < 'td' >.
Is it possible to develop the table like this through JavaScript?
function genera_tabla() {
var body = document.getElementsByTagName("body")[0];
var tabla = document.createElement("table");
var tblBody = document.createElement("tbody");
for (var i = 0; i < 4; i++) {
var hilera = document.createElement("th");
for (var j = 0; j < 4; j++) {
var celda = document.createElement("td");
var textoCelda = document.createTextNode("fila "+i+", columna "+j + "\n");
celda.appendChild(textoCelda);
hilera.appendChild(celda);
}
tblBody.appendChild(hilera);
}
tabla.appendChild(tblBody);
body.appendChild(tabla);
tabla.setAttribute("border", "2");
}
<html>
<input type="button" value="Genera una tabla" onclick="genera_tabla()">
</html>