scriptygoddess

03 Sep, 2007

document.getElementById … has no properties

Posted by: Jennifer In: Bookmarks

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

September 11th, 2007 at 6:14 am

Avatar

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

September 24th, 2007 at 8:01 am

Avatar

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

How stupid do I feel? 😉

3 | Chad Crowell

October 3rd, 2007 at 7:53 am

Avatar

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

January 22nd, 2008 at 4:50 am

Avatar

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

5 | Aaron

March 29th, 2008 at 9:33 pm

Avatar

#2 – I feel like a bloody idiot…

6 | peanutbutter

April 21st, 2008 at 3:14 pm

Avatar

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

7 | Haileigh

May 8th, 2008 at 12:54 pm

Avatar

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

8 | iceanfire

June 10th, 2008 at 4:39 pm

Avatar

#2 was killing me. Thank you!

9 | Russian_Aleksey

July 7th, 2008 at 1:35 am

Avatar

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

10 | CarlinWashington

July 22nd, 2008 at 12:43 am

Avatar

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

11 | david

July 27th, 2008 at 2:04 pm

Avatar

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 :(

Featured Sponsors

Genesis Framework for WordPress

Advertise Here


  • Scott: Just moved changed the site URL as WP's installed in a subfolder. Cookie clearance worked for me. Thanks!
  • Stephen Lareau: Hi great blog thanks. Just thought I would add that it helps to put target = like this:1-800-555-1212 and
  • Cord Blomquist: Jennifer, you may want to check out tp2wp.com, a new service my company just launched that converts TypePad and Movable Type export files into WordPre

About


Advertisements