Skip to content

Instantly share code, notes, and snippets.

@crispy-computing-machine
Created December 13, 2017 12:30
Show Gist options
  • Save crispy-computing-machine/0551586a3e59d5eb713f78b1cd865a94 to your computer and use it in GitHub Desktop.
Save crispy-computing-machine/0551586a3e59d5eb713f78b1cd865a94 to your computer and use it in GitHub Desktop.
Create Table With Javascript/jQuery
var testCount = 101;
// Main elements
var $table = $("<table>", {
'border':'1'
});
var $thead = $("<thead>");
var $tbody = $("<tbody>");
// Add some headers
for(headerNum = 1; headerNum < testCount; headerNum++){
$thead.append($('<th>', {
'text':'Column ' + headerNum
}));
}
// Add some rows
for(rowCount = 1; rowCount < testCount; rowCount++) {
newTr = $('<tr>');
for(rowColumnCount = 1; rowColumnCount < testCount; rowColumnCount++) {
newTr.append($('<td>', {
'text':'Row:' + rowCount + " Col:" + rowColumnCount,
}));
}
$tbody.append(newTr);
}
// Add table to DOM
$table.append($thead);
$table.append($tbody);
$table.appendTo("body");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment