ASM wrote:
[...]
For the moment I'm fighting with appendChild in a table a cloneNoded row.
That's work fine with FF, Opera and others except ... IE (of course)
I have yet to do a simplier test before coming to ask here what is wrong.
Remember that when encountering a table, browsers will insert a tbody
element into the DOM even if there isn't one in the source HTML (they
are mandatory elements but the tags are optional).
A common problem is attempting to append a new row to a table element
when you should append to a tbody element. Other browsers will tolerate
it and add the row to the tbody anyway, but not IE.
e.g. if 'el' is a reference to a table:
var aRow = el.rows[0].cloneNode(true );
el.appendChild( aRow);
will not work in IE. But:
var aRow = el.rows[0].cloneNode(true );
var lastRow = el.rows[el.rows.length - 1];
lastRow.parentN ode.insertBefor e(aRow, lastRow.nextSib ling);
will work (and in others too) because the parent of the lastRow is a
tbody, not a table.
There is a sample below. Of course I could have just used a tbody
element instead of the table when climbing the tree, this is just a demo.
<script type="text/javascript">
function cloneRow( el )
{
// Get the table - should use tbody but this is just for show
while (el.parentNode && 'table' != el.nodeName.toL owerCase()){
el = el.parentNode;
}
var aRow = el.rows[0].cloneNode(true );
// The next line won't work in IE
// el.appendChild( aRow);
// But these will
var lastRow = el.rows[el.rows.length - 1];
lastRow.parentN ode.insertBefor e(aRow, lastRow.nextSib ling);
}
</script>
<table border="1">
<tr>
<td onclick="cloneR ow(this)">Click me</td>
</tr>
</table>
[...]
--
Rob