Martin Honnen <ma*******@yahoo.de> wrote in news:44675a6f$0$11078
$9*******@newsread4.arcor-online.net:
King Albert wrote:
mytable=document.createElement("table");
Create a tbody e.g.
var tbody = document.createElement("tbody");
mytable.appendChild(tbody);
then insert the rows into the tbody e.g.
mytable.appendChild(myrow);
tbody.appendChild(myrow);
If the HTML parser parses the HTML table markup then it implicitly
creates a tbody child if it is not in the markup.
thx for your advise,
The alert box below now acknowledges 4 rows.
Thx very much,
Ward
<html>
<head>
<script>
var arr=[];
arr[0]="first row";
arr[1]="second row";
arr[2]="third row";
arr[3]="fourth row";
function domtable() {
var myrow, mytd, mytext, mytable, attr;
mytable=document.createElement("table");
mytable.id='mijntabel';
mytbody=document.createElement("tbody");
for (i=0; i < arr.length ;i++){
myrow=document.createElement("tr");
mytd=document.createElement("td");
mytext=document.createTextNode(arr[i]);
mytd.appendChild(mytext);
myrow.appendChild(mytd);
mytbody.appendChild(myrow);
}
mytable.appendChild(mytbody);
document.body.appendChild(mytable);
}
function howmanyrows() {
var eerstetabel = document.getElementsByTagName("tbody");
alert('the browser says that this table has ' + eerstetabel
[0].rows.length + ' rows, which is true');
}
</script>
</head>
<body>
<input type="button" value="run me first" onclick="domtable();">
<input type="button" value="then check the number of rows"
onclick="howmanyrows();">
</body>
</html>