views:

202

answers:

2

I'm adding new rows to a table dinamically, with this code:

tbody = document.getElementById('tbody');
tr = tbody.insertRow(-1);
tr.id = 'last';
th = tr.insertCell(0);
td = tr.insertCell(1);

But what I actually got are two TD cells. I want a TH, as you can see.

It says the tagName property isn't changeable.

How can I do this? Will I need to use 'normal' methods like createElement and appendChild?

+2  A: 

I don't see any official docs that allow you to do this.

W3C Documentation for TR / TR.insertCell

The createElement/appendChild will work though.

scunliffe
A: 

What I do is define the th first, such as TableHeaderRow thr = new TableHeaderRow(); Add cell to it, then add it to the table.

Estelle
as you can see by the sample code, i don't wanna a header row, but just a header cell.
Igoru