sectrix
09-02-2006, 11:24 PM
This seems to be the most basic thing in the world, but I can't figure it out for the life of me. My problem is when I try to use
document.getElementById, it returns null on firefox, IE 5 for Mac, and Safari. This is a test XHTML strict page that simply sets up a div with the id of area1.
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>
test page
</title>
<meta http-equiv = "Content-Type" content = "text/html" />
<script type = "text/javascript" src = "test.js"></script>
</head>
<body>
<div id="area1">
Hey Hey Hey
</div>
</body>
</html>
This page links to a javascript file, which contains the following:
var area = document.getElementById("area1");
alert(area);
The alert box always says null. If I replace getElementById("area1") with getElementsByTagName("div"), it says [object NodeList], like it should. But no matter what I do, getElementById always returns null.
What embarassingly simple thing am I missing??
document.getElementById, it returns null on firefox, IE 5 for Mac, and Safari. This is a test XHTML strict page that simply sets up a div with the id of area1.
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>
test page
</title>
<meta http-equiv = "Content-Type" content = "text/html" />
<script type = "text/javascript" src = "test.js"></script>
</head>
<body>
<div id="area1">
Hey Hey Hey
</div>
</body>
</html>
This page links to a javascript file, which contains the following:
var area = document.getElementById("area1");
alert(area);
The alert box always says null. If I replace getElementById("area1") with getElementsByTagName("div"), it says [object NodeList], like it should. But no matter what I do, getElementById always returns null.
What embarassingly simple thing am I missing??