文件:head 屬性

Baseline 已廣泛支援

此功能已成熟,可在多種裝置和瀏覽器版本上執行。自 ⁨2018 年 6 月⁩ 起在所有瀏覽器中可用。

Document 介面的只讀屬性 head 返回當前文件的 <head> 元素。

一個 HTMLHeadElement

示例

html
<!doctype html>
<head id="my-document-head">
  <title>Example: using document.head</title>
</head>
js
const theHead = document.head;

console.log(theHead.id); // "my-document-head";
console.log(theHead === document.querySelector("head")); // true

注意

document.head 是隻讀的。嘗試為該屬性賦值將默默失敗,或者在 嚴格模式 下會丟擲一個 TypeError

規範

規範
HTML
# dom-document-head-dev

瀏覽器相容性

另見