文档: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

浏览器兼容性

另见