I am creating a table with elements from a database. I am using this function to render the elements in the HTML
function tableToHTML(tableData) {
var table = document.createElement('table'),
tableBody = document.createElement('tbody');
tableData.forEach(function(rowData) {
var row = document.createElement('tr');
rowData.forEach(function(cellData) {
var cell = document.createElement('td');
cell.appendChild(document.createTextNode(cellData));
row.appendChild(cell);
});
tableBody.appendChild(row);
});
table.appendChild(tableBody);
document.body.appendChild(table);
}
Can I somehow assign id or class attributes to the created trs or tds within the javascript? I am using the Meteor framework, so jQuery is fair game if it is simpler to do with jQuery.