Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Revision 408415 of document.head

  • リビジョンの URL スラグ: Web/API/document.head
  • リビジョンのタイトル: document.head
  • リビジョンの ID: 408415
  • 作成日:
  • 作成者: ethertank
  • 現行リビジョン? いいえ
  • コメント DOM/document.head Web/API/document.head
タグ: 

このリビジョンの内容

概要

文書の {{HTMLElement("head")}} 要素を返します。 <head> 要素は文法上、{{HTMLElement("html")}} 要素直下にひとつのみ配置可能ですが、仮に <head> 要素が文書中に複数存在する場合、 document.head はそれらの内の最初の <head> 要素を返します。

構文

var objRef = document.head;

// ※ HTML 中に次の様な head 要素が存在すると仮定 : <head id="my-document-head">
var aHead = document.head;

alert(aHead.id);
// "my-document-head" が返る。head 要素の id を参照している事が見て取れる。

alert( document.head === document.querySelector("head") === document.getElementsByTagName("head")[0] );
// true が返る。これらが全て同一の要素を参照している事が見て取れる。

注記

document.head は読取専用です。このプロパティに値を代入した場合、エラーのスローを伴わずに失敗、もしくは Gecko ブラウザで ECMAScript ストリクトモードの場合は TypeError がスローされます。

ブラウザ実装状況

{{CompatibilityTable}}
機能 Chrome Firefox (Gecko) Internet Explorer Opera Safari
基本サポート 4.0 {{CompatGeckoDesktop("2")}} 9.0 11.0 5.0
機能 Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
基本サポート {{CompatVersionUnknown}} {{CompatGeckoMobile("2")}} 9.0 {{CompatVersionUnknown}} {{CompatVersionUnknown}}

仕様書

このリビジョンのソースコード

<h2 id="Summary" name="Summary">概要</h2>

<p>文書の {{HTMLElement("head")}} 要素を返します。 <code>&lt;head&gt;</code> 要素は文法上、{{HTMLElement("html")}} 要素直下にひとつのみ配置可能ですが、仮に <code>&lt;head&gt;</code> 要素が文書中に複数存在する場合、 <code>document.head</code> はそれらの内の最初の <code>&lt;head&gt;</code> 要素を返します。</p>


<h2 id="Syntax" name="Syntax">構文</h2>
<pre class="syntaxbox">
var <var>objRef</var> = document.head;
</pre>


<h2 id="Example" name="Example">例</h2>
<pre class="brush:js">
// ※ HTML 中に次の様な head 要素が存在すると仮定 : &lt;head id="my-document-head"&gt;
var aHead = document.head;

alert(aHead.id);
// "my-document-head" が返る。head 要素の id を参照している事が見て取れる。

alert( document.head === document.querySelector("head") === document.getElementsByTagName("head")[0] );
// true が返る。これらが全て同一の要素を参照している事が見て取れる。
</pre>


<h2 id="Example" name="Example">注記</h2>

<p><code>document.head</code> は読取専用です。このプロパティに値を代入した場合、エラーのスローを伴わずに失敗、もしくは Gecko ブラウザで ECMAScript ストリクトモードの場合は <code>TypeError</code> がスローされます。</p>

<h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザ実装状況</h2>
<div>{{CompatibilityTable}}</div>
<div id="compat-desktop">
  <table class="compat-table">
    <tbody>
      <tr>
        <th>機能</th>
        <th>Chrome</th>
        <th>Firefox (Gecko)</th>
        <th>Internet Explorer</th>
        <th>Opera</th>
        <th>Safari</th>
      </tr>
      <tr>
        <td>基本サポート</td>
        <td>4.0</td>
        <td>{{CompatGeckoDesktop("2")}}</td>
        <td>9.0</td>
        <td>11.0</td>
        <td>5.0</td>
      </tr>
    </tbody>
  </table>
</div>
<div id="compat-mobile">
  <table class="compat-table">
    <tbody>
      <tr>
        <th>機能</th>
        <th>Android</th>
        <th>Firefox Mobile (Gecko)</th>
        <th>IE Mobile</th>
        <th>Opera Mobile</th>
        <th>Safari Mobile</th>
      </tr>
      <tr>
        <td>基本サポート</td>
        <td>{{CompatVersionUnknown}}</td>
        <td>{{CompatGeckoMobile("2")}}</td>
        <td>9.0</td>
        <td>{{CompatVersionUnknown}}</td>
        <td>{{CompatVersionUnknown}}</td>
      </tr>
    </tbody>
  </table>
</div>


<h2 id="Specification" name="Specification">仕様書</h2>
<ul>
  <li><a href="https://www.w3.org/TR/html5/dom.html#dom-tree-accessors" title="https://www.w3.org/TR/html5/dom.html#dom-document-head">HTML5: DOM Tree Accessors</a></li>
</ul>
このリビジョンへ戻す