I'm creating an HTML table using JavaScript:
function CreateArray(){
var arr = [];
for(var i = 0 ; i < 10; i++){
arr.push({
firstName:"John",
lastName:"Doe",
email:"email"+i.toString()+"@gmail.com"
});
}
return arr;
}
function CreateTable(data) {
var tableStr = [];
var j = -1;
tableStr[++j] = '<table class="tftable" border="1"><thead><tr><th><input type="checkbox" id="allEmails" onclick = "SelectAllEmails()"/></th><th>First Name</th><th>Family Name</th><th>Email</th></tr></thead><tbody>';
for (var i = 0; i < data.length; i++) {
tableStr[++j] = '<tr><td>';
tableStr[++j] = '<input type= "checkbox"';
tableStr[++j] = 'id =' + "chbxEmail" + i.toString() +" "+'onclick =' + "foo(this)"+" "+'/>';
tableStr[++j] = '</td><td>';
tableStr[++j] = data[i].firstName;
tableStr[++j] = '</td><td>';
tableStr[++j] = data[i].lastName;
tableStr[++j] = '</td><td>';
tableStr[++j] = data[i].email;
tableStr[++j] = '</td></tr>';
}
tableStr[++j] = '</tbody></table>';
var table = tableStr.join('');
}
I need to get all rows inside the HTML table except the header row. I've tried it this way:
var trows = table.getElementsByTagName('tbody')[0].rows;
alert(trows.length);
But I don't get any result. Even the alert box is not displayed.
How can I get the rows inside the table variable without the header row?