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 June 2018.

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

一個 HTMLHeadElement

範例

html
<!doctype html>
<head id="my-document-head">
  <title>範例:使用 document.head</title>
</head>

<script>
  const theHead = document.head;

  console.log(theHead.id); // 「my-document-head」;

  console.log(theHead === document.querySelector("head")); // true
</script>

備註

document.head 是唯讀的。嘗試為此屬性賦值將會靜默失敗,或者在嚴格模式中拋出 TypeError

規範

Specification
HTML
# dom-document-head-dev

瀏覽器相容性

參見