Well, there are a few ways things can be done.
If the javascript is in the <head> and isn't in a function that's called by onload (preferrably by adding an event listener to the body IMHO) or at the end of the page then the script runs before the page's DOM is loaded in so the tags won't be there yet to get. eg. this won't work:
HTML Code:
<html><head><title>nodeName test</title>
<script type='text/javascript'>
var target = document.getElementById("movieTitle");
alert(target.nodeName);
</script>
</head>
<body>
<h4 id="movieTitle">Analyze This</h4>
<p>
The film stars Robert De Niro as a mafioso and Billy Crystal as a psychiatrist.
</p>
</body></html>
but this will:
HTML Code:
<html><head><title>nodeName test</title>
</head>
<body>
<h4 id="movieTitle">Analyze This</h4>
<p>
The film stars Robert De Niro as a mafioso and Billy Crystal as a psychiatrist.
</p>
<script type='text/javascript'>
var target = document.getElementById("movieTitle");
alert(target.nodeName);
</script>
</body></html>
*a quick and dirty example, but hopefully it helps
Bookmarks