...

View Full Version : Weid Problem(document.getElementById)



smokinguns
04-28-2009, 09:20 PM
Hey all,
I create a div element at run time and assign an ID to it.

var div=document.createElement('DIV');
div.id="mydiv"

When I use Firefox/IE explorer developer tool to view the DOM, the div is created and the id assigned, but when I try to access it using
document.getElementById("mydiv"), I get the "object is null " error.
I want to set the div's innerHTML and have been tearing my hair over this.
I read somewhere that by just creating the div using "createElement" and setting its id, One cant access it using the document.getElementById property

What gives??How do I access the div??

TinyScript
04-28-2009, 09:32 PM
I think you might have to use setAttribute or it might be that you have to use document.appendchild() before you can access it.

let's see that script! I wanna test it. heheh

TinyScript
04-28-2009, 09:36 PM
here's a link
http://codingforums.com/showthread.php?t=140561
and the code in the thread

smokinguns
04-29-2009, 04:44 AM
hey,
thanx for the prompt replies. I figured the problem. It was a stupid error on my part.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum