Hi,
I suspect this is a common question but I've read the FAQ and searched
the archives and couldn't find it. In a script embedded in the body of
the page I want to quickly find the last node that was created and
appendChild nodes to it. I can't just use document.body.a ppendChild as
the last node is likely to be a grandchild or great-grandchild of body.
I know that I could document.write an element with an id and then
getElementById but this slow and clunky, there must be a faster way,
document.write( ) knows where to put its output.
In case I've not made myself clear:
[...inside an HTML document...]
Some text
<script>text=do cument.createTe xtNode("DOM");</script>
<table>
<tr>
<td>elem 1</td>
<td>elem
2<script>docume nt.write("locat ion");document. body.appendChil d(text);</script></td>
</tr>
<tr>
<td>elem 3</td>
<td>elem 4</td>
</tr>
</table>
[...end of snippet...]
I'd like to replace document.body with something that would make the
text DOM appear after location rather than after the table and not
depend on the containing td having an id that I getElementById for.
Any help appreciated,
Jon.
I suspect this is a common question but I've read the FAQ and searched
the archives and couldn't find it. In a script embedded in the body of
the page I want to quickly find the last node that was created and
appendChild nodes to it. I can't just use document.body.a ppendChild as
the last node is likely to be a grandchild or great-grandchild of body.
I know that I could document.write an element with an id and then
getElementById but this slow and clunky, there must be a faster way,
document.write( ) knows where to put its output.
In case I've not made myself clear:
[...inside an HTML document...]
Some text
<script>text=do cument.createTe xtNode("DOM");</script>
<table>
<tr>
<td>elem 1</td>
<td>elem
2<script>docume nt.write("locat ion");document. body.appendChil d(text);</script></td>
</tr>
<tr>
<td>elem 3</td>
<td>elem 4</td>
</tr>
</table>
[...end of snippet...]
I'd like to replace document.body with something that would make the
text DOM appear after location rather than after the table and not
depend on the containing td having an id that I getElementById for.
Any help appreciated,
Jon.
Comment