Tom
Tom

Reputation: 6707

problem with document.getElementById accessing HEAD id="head"

I am accessing head,

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

Works with IE, not with Firefox..

Upvotes: 2

Views: 8122

Answers (4)

stefita
stefita

Reputation: 1793

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

Upvotes: 2

CalebD
CalebD

Reputation: 5022

Tested on Firefox 3 with Firebug:

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

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

Upvotes: 0

Gregoire
Gregoire

Reputation: 24832

<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

Upvotes: 1

Randell
Randell

Reputation: 6170

Use this instead:

document.getElementsByTagName("head")[0]

Upvotes: 3

Related Questions