SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Oct 2007
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy document.getElementById - Weird Problem

    I am using:

    Code:
    document.getElementById('box').innerHTML
    in one of my JS scripts to get the value inside a <span></span> tag. Most of the time it works, however sometimes it fails to read / see the object (span tag).

    In Mozilla Error Console it then says "document.getElementById('box').innerHTML has no properties". In other words the JS fails to see / read it. This happens randomly...most of the time it works, but like I said sometimes this happens. Happens in both IE and FF. With this code I am reading the value in these tags every second (every 1000 milliseconds), maybe this has something to do with it?

    Anyone know how / why this could happen? Any way to fix it? Or use another way to get the value inside of a <span> or <div> tag?

    I greatly appreciate any help!

  2. #2
    SitePoint Evangelist
    Join Date
    Mar 2006
    Location
    Sweden
    Posts
    451
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sounds like you access the element before it's has been read into the DOM. When are you reading the elements innerHTML? Could you post some code?

  3. #3
    SitePoint Member
    Join Date
    Oct 2007
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well, I'm loading a page using AJAX, and the script starts 1 second after the ajax page (which contains the <span> tag) has been loaded.

    How long does it usually take before the things are read into the DOM?


Bookmarks

Posting Permissions

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