make a table within figure in javascript

To make a table within figure in JavaScript, you need to create an HTML table element by dynamically adding the HTML tags using JavaScript. You can then style the CSS of the table as required.

Here is an example code snippet to create a table within a figure using JavaScript:

index.tsx
// create a figure element
var figure = document.createElement("figure");

// create a table element
var table = document.createElement("table");

// create table rows and cells dynamically
for (var i = 0; i < numberOfRows; i++) {
  var row = document.createElement("tr");
  for (var j = 0; j < numberOfColumns; j++) {
    var cell = document.createElement("td");
    cell.textContent = "Content";
    row.appendChild(cell);
  }
  table.appendChild(row);
}

// add the table to the figure element
figure.appendChild(table);

// add the figure to the document body
document.body.appendChild(figure);
599 chars
23 lines

You can then style the CSS of the table and figure as required using CSS. For example:

figure {
  border: 1px solid gray;
  padding: 10px;
}

table {
  border-collapse: collapse;
}

td {
  border: 1px solid black;
  padding: 5px;
}
145 chars
14 lines

This will create a figure element with a gray border and padding, containing a table with black-bordered cells with padding.

related categories

gistlibby LogSnag