Skip to content

Instantly share code, notes, and snippets.

@alexalannunes
Created December 11, 2020 03:56
Show Gist options
  • Save alexalannunes/b6eebd4062323fe652db8620c88866c2 to your computer and use it in GitHub Desktop.
Save alexalannunes/b6eebd4062323fe652db8620c88866c2 to your computer and use it in GitHub Desktop.
table generator
const app = document.querySelector('#app')
const columns = 10;
const rows = 10;
const table = document.createElement('table');
table.border=1;
for (var i = 0; i < rows; i++) {
const tr = document.createElement('tr')
for (var j = 0; j < columns; j++) {
const td = document.createElement('td')
td.textContent = j == 0 ? i : j;
td.onclick = selectTd;
tr.append(td)
}
table.append(tr)
}
app.append(table)
function selectTd() {
this.style.background = 'red'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment