Jump to content

innerHTML Question


cmattoon

Recommended Posts

I borrowed a free script to make a basic news scroller with the use of an XML file. Basically, it loads the XML file, then does:

 

 document.all.write('<div id="news_panel"></div>');

 

Later on in the script, it does:

document.all.getElementById(news_panel).innerHTML = '.......';

 

Up until recently, this has worked fine because it was on a test page by itself. However, when I integrate into the existing main page, I can't seem to put it where I want it.

 

When I code the DIV as HTML, it doesn't want to write into that DIV using the 2nd line of code (above). It only seems to write when the DIV is written through the document.all.write() method.

 

The other thing I tried was to code (in HTML) a <div id="mainNewsFrame"></div> and then write the news_panel DIV into the mainNewsFrame DIV, but that doesn't work either.

 

I'm not sure what the document.ALL.getElementById() means either.. in previous JavaScript code I've seen, it's simply "document.write" or "document.getElementById()".. any idea what the "all" is for?

 

(If you can't tell, I'm not very familiar with JavaScript!)

 

Thanks!

Link to comment
Share on other sites

My guess is that free script is ancient garbage.

Don't use document.write(). I haven't seen document.all.* used in so long I don't even remember what it does anymore.

if your html contains <div id="news_panel"></div>, then document.getElementById('news_panel').innerHTML = '......' should work just fine.

if you need to add html elements to the document at runtime, either set or append it to document.body.innerHTML or create the DOM element with document.createElement('div') and then use appendChild() on what ever parent element you want to append it to.

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.