Hi,
I am trying to learn how to dynamically write HTML using the W3C DOM.
But I am having trouble with the code. It doesn't seem to be doing
what I expect it to and I am not sure why.
Let me give an example.
document.getEle mentsByTagName( "head")[0].appendChild(do cument.createEl ement("title")) ;
alert(document. getElementsByTa gName("title")[0].tagName);
document.getEle mentsByTagName( "title")[0].appendChild(cr eateTextNode("A ssignment
6"));
This code produces an error ("Object expected") on the 3rd line. I am
sure that the <title> tag has been created because the second line
produces a message box with "TITLE" in it.
Any ideas what's going wrong??
I am trying to learn how to dynamically write HTML using the W3C DOM.
But I am having trouble with the code. It doesn't seem to be doing
what I expect it to and I am not sure why.
Let me give an example.
document.getEle mentsByTagName( "head")[0].appendChild(do cument.createEl ement("title")) ;
alert(document. getElementsByTa gName("title")[0].tagName);
document.getEle mentsByTagName( "title")[0].appendChild(cr eateTextNode("A ssignment
6"));
This code produces an error ("Object expected") on the 3rd line. I am
sure that the <title> tag has been created because the second line
produces a message box with "TITLE" in it.
Any ideas what's going wrong??
Comment