scriptygoddess RSS Feed
 
 
 
 

document.getElementById … has no properties

This isn't a big deal, but it was something I was fighting with for a bit. If you're trying to set the properties of a DIV via javascript, and you're getting the "document.getElementById("mydiv") has no properties" javascript warning, there's probably two big things that will cause it.

1) you didn't set the id.
Go back and make sure your div has id="mydiv" (or whatever you named it) in there.

2) the javascript is running BEFORE the div has been defined in the code.
This is what got me. I had the javascript code just above where the div was… and at load time, that div doesn't exist yet… the browser hasn't gotten that far down the page yet, so as far as it's concerned, that div with that id, doesn't exist. Once I moved the javascript BELOW the div… all was well.

And actually here - they suggest calling it on onload.

11 Responses to “document.getElementById … has no properties”

  1. 1
    Matthias:

    alternatively you can figure out loading things like this ondomready. Find versions of it as part of mootools, jquery, or the original hack on dean edwards site, er, here:
    http://dean.edwards.name/weblog/2006/06/again/

  2. 2
    Keir:

    Cheers for that - I was a victim of number 2 for a WEEK.

    How stupid do I feel? ;-)

  3. 3
    Chad Crowell:

    OMG thank you! I have one of your scripts bookmarked and happened to click through to your homepage and this quickly addressed a problem I've been avoiding on a site thats launching next week!

  4. 4
    suritam9:

    Thank you!! FF doesn't suppot 'name' alone, but IE6 Does. Your answer is very good!!

  5. 5
    Aaron:

    #2 - I feel like a bloody idiot…

  6. 6
    peanutbutter:

    #2 — put me in the ranks of 'bloody idiot' as well :-O Thanks!

  7. 7
    Haileigh:

    OMG! thank you so much!!! #2 … sigh…

  8. 8
    iceanfire:

    #2 was killing me. Thank you!

  9. 9
    Russian_Aleksey:

    #2! I was so stupid! Thank you VERY MUCH!!!

  10. 10
    CarlinWashington:

    One more fool here you helped with #2. Thanks!

  11. 11
    david:

    yes, uff, 5 hours searching and comparing. just the () in window.onload = initAll() broke it - thanks to you i started searching in the right spot… #2 sucks and in the tutorials i read they didn't really point out that possibility :(

Leave a Reply

Bookmarks

WordPress Resources

Meta

Random Stuff