tags:

views:

392

answers:

4

I am accessing head,

var head = document.getElementById("head");

Works with IE, not with Firefox..

+3  A: 

Use this instead:

document.getElementsByTagName("head")[0]
Randell
+2  A: 
<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>

work fine in firefox. but if you script is in the header and is runned automaticcally it could not work as the header is not fully loaded

Gregoire
A: 

Tested on Firefox 3 with Firebug:

>>> document.getElementById('head')
<head id="head">

Are you sure your head element has an ID of head?

CalebD
+1  A: 

I think the attribute id is not allowed in this particular tag.

stefita
That is correct: `id` is not a valid attribute for the `<head>` tag in HTML.
Nate
Can you provide us with link where are listed tags which cannot have id ? I am interrested particurarly in FRAME tag
ante.sabo
http://www.w3.org/TR/REC-html40/present/frames.html#edef-FRAME
stefita