Reputation: 809
Inside table td i have control(s). there must be one control inside td but can be multiple. I can get first control the following way.
ctrlTable.rows[i].cells[1].getElementsByTagName("*")[0].value;
So how to check whether the "td"/cell[1] has more control
Thanks,
Upvotes: 0
Views: 770
Reputation: 175768
One way;
function countEls(cell) {
var lookFor = ["INPUT", "SELECT", "BUTTON"];
var count = 0;
for (var i = 0; i < lookFor.length; i++) {
count += cell.getElementsByTagName(lookFor[i]).length;
}
return count;
}
alert(countEls(ctrlTable.rows[i].cells[1]));
Upvotes: 1
Reputation: 49385
To check the number of children on any DOM element, you can use the childNodes[]
property, e.g.:
ctrlTable.rows[i].cells[1].childNodes.length > 0
Upvotes: 1