Professional Documents
Culture Documents
Here is the rew
Here is the rew
Here is the rew
```
table.appendChild(thead);
table.appendChild(tbody);
// Create new table header cells and add them to the row
row.appendChild(heading1);
let heading2 = document.createElement("th");
row.appendChild(heading2);
row.appendChild(heading3);
thead.appendChild(row);
row.appendChild(cell1);
row.appendChild(cell2);
let cell3 = document.createElement("td");
row.appendChild(cell3);
tbody.appendChild(row);
tableContainer.appendChild(table);
```
I added comments to explain each section of the code, making it easier to understand what the code is
doing. Let me know if you have any further questions!
Here is a simple JavaScript program that creates a table using HTML and CSS:
HTML:
```
<!DOCTYPE html>
<html>
<head>
<title>Table Example</title>
<style>
table {
border-collapse: collapse;
width: 100%;
th, td {
padding: 10px;
text-align: left;
th {
background-color: #f0f0f0;
</style>
</head>
<body>
<div id="table-container"></div>
<script src="script.js"></script>
</body>
</html>
```
```
let tableContainer = document.getElementById("table-container");
table.appendChild(thead);
table.appendChild(tbody);
row.appendChild(heading1);
row.appendChild(heading2);
row.appendChild(heading3);
thead.appendChild(row);
for (let i = 0; i < 5; i++) {
row.appendChild(cell1);
row.appendChild(cell2);
row.appendChild(cell3);
tbody.appendChild(row);
tableContainer.appendChild(table);
```
This program creates a simple table with three columns and five rows, using HTML elements and CSS
styling. The JavaScript code dynamically creates the table and its content, and appends it to the page.
Note: You need to have both the HTML file and the JavaScript file (script.js) in the same directory for this
to work.
Sure, here's a simple JavaScript program that creates a table using HTML and CSS. The program creates a
table with 3 rows and 3 columns, and then applies some basic styling using CSS.
```javascript
document.body.appendChild(table);
```
Here's the accompanying HTML and CSS for styling the table:
HTML:
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Table Creation</title>
</head>
<body>
<script src="script.js"></script>
</body>
</html>
```
CSS (styles.css):
```css
table {
border-collapse: collapse;
width: 100%;
td {
text-align: center;
padding: 8px;
tr:nth-child(even) {
background-color: #f2f2f2;
th {
background-color: #4CAF50;
color: white;
```
This JavaScript program creates a table dynamically using the DOM, and the accompanying HTML and
CSS provide the structure and styling for the table.