Issue with document.getElementById accessing HEAD id = "head"
I turn to the chapter
var head = document.getElementById ("head");
Works with IE, not Firefox ..
+2
Tom
source
to share
4 answers
Use this instead:
document.getElementsByTagName("head")[0]
+3
Randell
source
to share
I think the attribute id is not allowed in this particular tag.
+2
stefita
source
to share
<html>
<head id="head">
<script type="text/javascript" src="jquery-1.3.1.min.js" ></script>
</head>
<body>
<script type="text/javascript">
alert(document.getElementById("head"));
</script>
</body>
</html>
works great in firefox. but if you script is in header and runs automatically, it cannot work as header is not fully loaded
+1
Gregoire
source
to share
Tested on Firefox 3 with Firebug:
>>> document.getElementById('head')
<head id="head">
Are you sure your head element has a head ID?
0
CalebD
source
to share