469,332 Members | 6,649 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,332 developers. It's quick & easy.

Problem with document.getElementById

I am writing a pretty simple Javascript which makes use of getElementById to work with some divs on the page.

The divs are labelled correctly (id="whatever") and there are no duplicate div ids.

I have tried addressing the divs using:

document.getElementById("whatever") as well as

In all cases, I am getting nothing but a null value returned.

I'm using the XHTML Transitional 1.1 doctype and am seeing this problem occur on all testing browsers. I have validated the HTML of the page and it's fine.

I've even used Firefox to display all divs on the page, and they are all showing up exactly as coded.

Any suggestions?

-- Gary
Dec 5 '06 #1
4 1550
1,208 Expert 1GB
well with just getting the element all your are getting is the object what are you trying todo with the divs
Dec 5 '06 #2
1,892 Expert 1GB
Post the code that isn't working I'm sure we'll be able to spot an error like this immediately.
Dec 5 '06 #3

I posted copies of all the relevant files at:


For the Javascript, I created just a simple script that would grab the id of a div that I knew exists in the code and put it in an alert statement, just so that I could figure out what I am doing wrong. But the alert always says "null"

Thanks for all your help folks.
Dec 6 '06 #4
1,892 Expert 1GB
Not sure what's going on but this works:

[html]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<title>Test Get Element By ID</title>

<script type="text/javascript">

function Something()
var Navigation = document.getElementById("navigation")





<body onload="Something();">

<div id="navigation">
<ul id="navmenu">
<li><a href="/content/index.cfm?cID=1645" target="_self">Great Deals<br /><img src="../images/designtest/concierge.gif" width="71" height="71" alt="Great Deals" /></a>
<li><a href="/content/index.cfm?cID=1646" target="_self">Great Deal 1</a></li>
<li><a href="/content/index.cfm?cID=1652" target="_self">Long content</a></li>
<li><a href="/content/index.cfm?cID=1651" target="_self">Signup Page</a></li>
<li><a href="/content/index.cfm?cID=1647" target="_self">More Deals<br /><img src="../images/designtest/concierge.gif" width="71" height="71" alt="More Deals" /></a>
<li><a href="/content/index.cfm?cID=1648" target="_self">Info page</a></li>
<li><a href="/content/index.cfm?cID=1649" target="_self">Test frame</a></li>
<li><a href="/content/index.cfm?cID=1650" target="_self">Test frame 2</a></li>
<li><a href="/content/index.cfm?cID=1653" target="_self">Fun Deals<br /><img src="../images/designtest/concierge.gif" width="71" height="71" alt="Fun Deals" /></a>
<li><a href="/content/index.cfm?cID=1657" target="_self">Page 1</a></li>
<li><a href="/content/index.cfm?cID=1654" target="_self">Hot Deals<br /><img src="../images/designtest/concierge.gif" width="71" height="71" alt="Hot Deals" /></a>
<li><a href="/content/index.cfm?cID=1658" target="_self">Page 1</a></li>
<li><a href="/content/index.cfm?cID=1655" target="_self">Cool Deals<br /><img src="../images/designtest/concierge.gif" width="71" height="71" alt="Cool Deals" /></a>
<li><a href="/content/index.cfm?cID=1659" target="_self">Page 1</a></li>
<li><a href="/content/index.cfm?cID=1656" target="_self">Latest Deals<br /><img src="../images/designtest/concierge.gif" width="71" height="71" alt="Latest Deals" /></a>
<li><a href="/content/index.cfm?cID=1660" target="_self">Page 1</a></li>


Dec 6 '06 #5

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

4 posts views Thread by tcole6 | last post: by
2 posts views Thread by K. | last post: by
7 posts views Thread by raknin | last post: by
2 posts views Thread by swethak | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by Marylou17 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.