[RESOLVED] FireFox document.write() rendering not in documen

wxdqz

New Member
Hi,

I have a problem using Javascript with Firefox. The problem is as follows...

document.write("<span id='mySpan'>Hello</span>");

This line writes out a span tag with id="mySpan". When I try to access this element through
Javascript using the command

alert(document.getElementById("mySpan"));

it returns null. However, when i just write the <span> tags into my HTML file rather than
writing it in using document.write(), it returns the element.

It is obvious to me, and after quite a bit of fiddling, that document.getElementById() will
not access document elements that have been written in using document.write(). So, how do I
get access to these elements? I took a long look through the DOM for Firefox but I couldn't
find anything. I presume there must be a command like document.script.getElementById() or
document.final.getElementById() that will grab the elements AFTER they were written using
document.write()

Oh, I also tried to access these document.write() elements using things like getElementsByTagName()
and the such, still returned null every time. I have done JavaScript for a while, and there
are no other errors in the code I am using. The code works in IE and Netscape because they
treat the document object as being AFTER the document.write() commands has executed, not before
like Firefox appears to do.

Thanks guys, your answers will be greatly appreciated.

WATTO
<!-- e --><a href="mailto:[email protected]">[email protected]</a><!-- e -->
<!-- m --><a class="postlink" href="http://www.watto.org">http://www.watto.org</a><!-- m -->
 
Top