Scripting techniques - 2.2 Dynamic Content

In 2.2 Dynamic content generation, in the code sample shouldn't
createTextNode() and appendChild be used instead of insertText (which
I don't believe is valid or was copied from code referencing custom
methods)?

This worked for me:

function fillContent() {
       // parentelem is a specified element in the DOM - OR uncomment below
       // var docelems=document.getElementsByTagName("body");
       // var parentelem=docelems.item(0);
       var htext=document.createTextNode("This is test text.");
       var header = document.createElement("h1");
       header.appendChild(htext);
       var para = document.createElement("p");
       var ptext=document.createTextNode("This is test text.");
       para.appendChild(ptext);
       var list = document.createElement("ul");
       itemone = document.createElement("li");
       itemonelink=document.createElement("a");
       itemonelink.setAttribute("href","foo.html");
       var itemonelinktext=document.createTextNode("This is test text.");
       itemone.appendChild(itemonelink);
       list.appendChild(itemone);
       itemonelink.appendChild(itemonelinktext);
       parentelem.appendChild(header);
       parentelem.appendChild(para);
       parentelem.appendChild(list);
}

Received on Saturday, 20 November 2004 01:18:53 UTC