Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Apr 2009
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Weid Problem(document.getElementById)

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

  • #2
    Regular Coder
    Join Date
    Mar 2009
    Location
    Portland Oregon
    Posts
    690
    Thanks
    44
    Thanked 63 Times in 62 Posts
    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

  • #3
    Regular Coder
    Join Date
    Mar 2009
    Location
    Portland Oregon
    Posts
    690
    Thanks
    44
    Thanked 63 Times in 62 Posts
    here's a link
    Assign id upon createElement??
    and the code in the thread

  • #4
    New to the CF scene
    Join Date
    Apr 2009
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    hey,
    thanx for the prompt replies. I figured the problem. It was a stupid error on my part.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •