I have been trying to create a table dynamically based on an array return from another function.
I have 2 array :
var listOfNames = ['a', 'b', 'c'];
var scoreLabels = ['Query', 'Entry', '% Matched', 'Alignment Len', 'Mismatches', 'Gaps', 'E-Value', 'Bitscore'];
The first array will contain element which will be id of each row.
The second array is the list of columns for each row.
My html looks like this
<table>
<tbody></tbody>
</table>
and the for loop that I have written looks like this :
for (var i = 0; listOfNames.length < i; i++) {
var row = $('<tr></tr>');
$(row).attr('id', listOfNames[i]);
for (var x = 0; scoreLabels.length < x; x++) {
var tableHeader = $('<td></td>');
$(tableHeader).attr('text', scoreLabels[x]);
$(tableHeader).appendTo(row);
}
$(row).appendTo('table');
}
I have been looking at other posts that teaches the creation of table dynamically with jquery, but to no avail.
Please kindly advice and let me know where i went wrong .
The js fiddle can be found here