Welcome to WebmasterWorld Guest from

Forum Moderators: incrediBILL

Message Too Old, No Replies

Adding multiple nodes in one go

1:06 pm on Jul 30, 2001 (gmt 0)

10+ Year Member

Is there a simple way of adding nodes in one go using DOM? For example I have the following code:

function addMyNode() {
node = document.getElementById("#001");
element = document.createElement('li');
text = document.createTextNode('Child 2');
element.appendChild(text, null);
node.appendChild(element, null);

Called with:
<ul id="#001">
<li>Child 1</li>
<input type="button" value="Insert new Node" onClick="addMyNode()"></input>

I wanted to use a DocumentFragment to append several children in one go, but the method createDocumentFragment just returns an empty one, as opposed to parsing the contents of a parameter. Anyone have any ideas?

2:51 pm on Jul 30, 2001 (gmt 0)

10+ Year Member

Hi Neil
The only idea I have using the function addMyNode would be to load an array and put it in a loop.
I am sure you already know but the js you are using will only work in ie 5.x and nn 6.
3:26 pm on Jul 30, 2001 (gmt 0)

10+ Year Member

Yep, thats the advantage of making an intranet oriented product. We get to choose what browsers we will code for ;)