create a table dynamically with javascript


create a table dynamically with javascript

how to create a table automatically with javascript and html

create a table dynamically with javascript
create a table dynamically with javascript

to create a table dynamically, that looks like an array, for an array tour:

        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
       <input type="button" value="Genera una tabla" onclick="genera_tabla()">
    function genera_tabla() {
          var tamañoi=10;
           var tamañoj=10;
 // Get the reference of the body element
  var body = document.getElementsByTagName("body")[0];
 // Create a <table> element and a <tbody> element
  var tabla   = document.createElement("table");
  var tblBody = document.createElement("tbody");
 // Create the cells
  for (var i = 0; i < tamañoi; i++) {
   // Create the rows of the table
    var hilera = document.createElement("tr");
    for (var j = 0; j < tamañoj; j++) {
 // Create a <td> element and a text node, make the node
       // text be the content of <td>, place the <td> element at the end
       // of the row of the table
      var celda = document.createElement("td");
      var textoCelda = document.createTextNode("["+i+","+j+"]");
 // add the row to the end of the table (at the end of the tblbo elementdy)
  // position the <tbody> under the <table> element
  // append <table> into <body>
  // modify the "border" attribute of the table and set it to "2";
  tabla.setAttribute("border", "2");

Post a Comment