This page was translated from English by the community. Learn more and join the MDN Web Docs community.

View in English Always switch to English

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 ⁨июнь 2018 г.⁩.

Возвращает элемент <head> текущего документа. Если имеется более одного элемента <head>, будет возвращён первый из них.

Синтаксис

var objRef = document.head;

Значение

HTMLHeadElement.

Пример

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

<script>
  var theHead = document.head;

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

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

Примечание

document.head доступно только для чтения. Присвоить значение этому свойству нельзя. При попытке это сделать ошибка вызвана не будет, только если вы не используете Strict Mode. В данном случае будет вызвано TypeError .

Спецификации

Specification
HTML
# dom-document-head-dev

Совместимость с браузерами

Смотрите также