<table id="table"></table>
let table = document.querySelector('#table');
let employees = [
{ name: 'employee1', age: 30, salary: 400 },
{ name: 'employee2', age: 31, salary: 500 },
{ name: 'employee3', age: 32, salary: 600 },
];
employees.forEach((employee) => {
let tr = document.createElement('tr');
table.appendChild(tr);
for(prop in employee) {
let td = document.createElement('td');
td.textContent = employee[prop];
tr.appendChild(td);
if (prop === 'age') {
td.addEventListener('click', (el) => {
el.target.textContent = parseInt(el.target.textContent) + 1;
});
};
};
});
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.