View Full Version : Weid Problem(document.getElementById)

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

var div=document.createElement('DIV');

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??

04-28-2009, 10: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

04-28-2009, 10:36 PM
here's a link
and the code in the thread

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