Document.head
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
回傳當前文件的 <head>
元素。如果該文件有超過一個 <head>
元素,那只會回傳第一個 <head>
元素。
語法
var objRef = document.head;
範例
js
// 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 |
---|
HTML # dom-document-head-dev |
瀏覽器相容性
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
head |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
- Partial support
- Partial support
- Has more compatibility info.
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.