Document.head

回傳當前文件的 <head> 元素。如果該文件有超過一個 <head> 元素,那只會回傳第一個 <head> 元素。

語法

var objRef = document.head;

範例

// in HTML: <head id="my-document-head">
var aHead = document.head;

alert(aHead.id); // "my-document-head";

alert( document.head === document.querySelector("head") ); // true

備註

document.head 是「唯讀」。若是想要將 document.head 改成別的值會失敗,這時有些瀏覽器不會告知任何錯誤訊息;有些,例如在 ECMAScript Strict 模式下 的 Gecko 瀏覽器,會給出 TypeError 異常。

規範

Specification Status Comment
WHATWG HTML Living Standard
The definition of 'Document.head' in that specification.
Living Standard Initial definition.
HTML 5.1
The definition of 'Document.head' in that specification.
Recommendation  
HTML5
The definition of 'Document.head' in that specification.
Recommendation  

瀏覽器相容性

Feature Chrome Edge Firefox (Gecko) Internet Explorer Opera Safari
Basic support 4.0 (Yes) 4.0 (2) 9.0 11.0 5.0
Feature Android Edge Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support (Yes) (Yes) 4.0 (2) 9.0 (Yes) (Yes)

參見

文件標籤與貢獻者

 此頁面的貢獻者: jackblackevo, Shiyou
 最近更新: jackblackevo,