Connecting Tech Pros Worldwide Help | Site Map

Problem dynamically writing HTML with W3C DOM

 
LinkBack Thread Tools Search this Thread
  #1  
Old December 6th, 2005, 04:07 PM
ezmiller
Guest
 
Posts: n/a
Default Problem dynamically writing HTML with W3C DOM

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.getElementsByTagName("head")[0].appendChild(document.createElement("title"));
alert(document.getElementsByTagName("title")[0].tagName);

document.getElementsByTagName("title")[0].appendChild(createTextNode("Assignment
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??


  #2  
Old December 6th, 2005, 04:25 PM
Christopher Benson-Manica
Guest
 
Posts: n/a
Default Re: Problem dynamically writing HTML with W3C DOM

ezmiller <ethanzanemiller@gmail.com> wrote:
[color=blue]
> document.getElementsByTagName("head")[0].appendChild(document.createElement("title"));
> alert(document.getElementsByTagName("title")[0].tagName);[/color]
[color=blue]
> document.getElementsByTagName("title")[0].appendChild(createTextNode("Assignment
> 6"));[/color]
[color=blue]
> Any ideas what's going wrong??[/color]

It may not fix all your troubles, but createTextNode() is a method of
the document object.

document.getElementsByTagName("title")[0].appendChild(document.createTextNode("Assignment 6"));
^^^^^^^^

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
  #3  
Old December 6th, 2005, 05:15 PM
ezmiller
Guest
 
Posts: n/a
Default Re: Problem dynamically writing HTML with W3C DOM

Right, I caught that just after I posted, but see my new message, where
after I fix that I get an error message: "Unexpected call to method or
property access."...

 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.