Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

create html table with javascript

let table = document.createElement('table');
let thead = document.createElement('thead');
let tbody = document.createElement('tbody');

table.appendChild(thead);
table.appendChild(tbody);

// Adding the entire table to the body tag
document.getElementById('body').appendChild(table);

// Creating and adding data to first row of the table
let row_1 = document.createElement('tr');
let heading_1 = document.createElement('th');
heading_1.innerHTML = "Sr. No.";
let heading_2 = document.createElement('th');
heading_2.innerHTML = "Name";
let heading_3 = document.createElement('th');
heading_3.innerHTML = "Company";

row_1.appendChild(heading_1);
row_1.appendChild(heading_2);
row_1.appendChild(heading_3);
thead.appendChild(row_1);


// Creating and adding data to second row of the table
let row_2 = document.createElement('tr');
let row_2_data_1 = document.createElement('td');
row_2_data_1.innerHTML = "1.";
let row_2_data_2 = document.createElement('td');
row_2_data_2.innerHTML = "James Clerk";
let row_2_data_3 = document.createElement('td');
row_2_data_3.innerHTML = "Netflix";

row_2.appendChild(row_2_data_1);
row_2.appendChild(row_2_data_2);
row_2.appendChild(row_2_data_3);
tbody.appendChild(row_2);
Comment

PREVIOUS NEXT
Code Example
Javascript :: how to get the text from an input field 
Javascript :: updating an array of object in mongoose 
Javascript :: documentation tool for angular applications 
Javascript :: npm paypal express checkout 
Javascript :: save sort order of jquery sortable 
Javascript :: how to connect mongodb with next js 
Javascript :: get string from textbox javascript 
Javascript :: javascript querySelector change input value 
Javascript :: js number padding to number of characters 
Javascript :: swift encode json 
Javascript :: create cookie javascript react 
Javascript :: append string js 
Javascript :: post method in reactjs hooks. 
Javascript :: filter js object array based on multiple parameters 
Javascript :: represent body in javascript 
Javascript :: dart json serializable 
Javascript :: vue js change delimiters 
Javascript :: address 
Javascript :: date javascript 
Javascript :: react native update state array of objects 
Javascript :: var in js 
Javascript :: process nexttick 
Javascript :: export function javascript 
Javascript :: how to update state in react 
Javascript :: how to make javascript function consise 
Javascript :: convert json data to a html table 
Javascript :: javascript check if it has passed midnight 
Javascript :: how to sepaarte text in object javascript 
Javascript :: how to do when enter is pressed javascript do smething 
Javascript :: jsx not working in react vscode 
ADD CONTENT
Topic
Content
Source link
Name
5+5 =