概要
文書の {{HTMLElement("head")}} 要素を返します。 <head>
要素は文法上、{{HTMLElement("html")}} 要素直下にひとつのみ配置可能ですが、仮に <head>
要素が文書中に複数存在する場合、 document.head
はそれらの内の最初の <head>
要素を返します。
構文
var objRef = document.head;
例
// ※ HTML 中に次の様な head 要素が存在すると仮定 : <head id="my-document-head"> var aHead = document.head; alert(aHead.id); // "my-document-head" が返る。head 要素の id を参照している事が見て取れる。 alert( document.head === document.querySelector("head") === document.getElementsByTagName("head")[0] ); // true が返る。これらが全て同一の要素を参照している事が見て取れる。
注記
document.head
は読取専用です。このプロパティに値を代入した場合、エラーのスローを伴わずに失敗、もしくは Gecko ブラウザで ECMAScript ストリクトモードの場合は TypeError
がスローされます。
ブラウザ実装状況
{{CompatibilityTable}}
機能 | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
基本サポート | 4.0 | {{CompatGeckoDesktop("2")}} | 9.0 | 11.0 | 5.0 |
機能 | Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|
基本サポート | {{CompatVersionUnknown}} | {{CompatGeckoMobile("2")}} | 9.0 | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} |