DOMImplementation.createDocument()

  • Revision slug: Web/API/DOMImplementation.createDocument
  • Revision title: DOMImplementation.createDocument
  • Revision id: 455397
  • Created:
  • Creator: teoli
  • Is current revision? No
  • Comment

Revision Content

{{DOMRef("DOMImplementation")}}

The DOMImplementation.createDocument() method creates and returns an {{domxref("XMLDocument")}}.

Syntax

doc = document.implementation.createDocument(namespaceURI, qualifiedNameStr, documentType);

Parameters

namespaceURI
Is a {{domxref("DOMString")}} containing the namespace URI of the document to be created, or null if the document doesn't belong to one.
qualifiedNameStr
Is a {{domxref("DOMString")}} containing the qualified name, that is an optional prefix and colon plus the local root element name, of the document to be created.
documentType
Is the DocumentType of the document to be created.

Example

var doc = document.implementation.createDocument ('http://www.w3.org/1999/xhtml', 'html', null);
var body = document.createElementNS('http://www.w3.org/1999/xhtml', 'body');
body.setAttribute('id', 'abc');
doc.documentElement.appendChild(body);
alert(doc.getElementById('abc')); // [object HTMLBodyElement]

Specifications

Specification Status Comment
{{SpecName('DOM WHATWG', '#dom-domimplementation-createdocument', 'DOMImplementation.createDocument')}} {{Spec2('DOM WHATWG')}} Modified the return type of createDocument() from {{domxref("Document")}} to {{domxref("XMLDocument")}}.
{{SpecName('DOM3 Core', 'core.html#Level-2-Core-DOM-createDocument', 'DOMImplementation.createDocument')}} {{Spec2('DOM3 Core')}} No change from {{SpecName("DOM2 Core")}}
{{SpecName('DOM2 Core', 'core.html#Level-2-Core-DOM-createDocument', 'DOMImplementation.createDocument')}} {{Spec2('DOM2 Core')}} Initial definition.

Browser compatibility

{{CompatibilityTable}}

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support {{CompatVersionUnknown}} {{CompatGeckoDesktop("1.0")}} 9.0 {{CompatVersionUnknown}} {{CompatVersionUnknown}}
Feature Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support {{CompatVersionUnknown}} {{CompatGeckoMobile("1.0")}} {{CompatVersionUnknown}} {{CompatVersionUnknown}} {{CompatVersionUnknown}}

See also

  • The {{domxref("DOMImplementation")}} interface it belongs to.

Revision Source

<p>{{DOMRef("DOMImplementation")}}</p>
<p>The <strong><code>DOMImplementation.createDocument()</code></strong> method creates and returns an {{domxref("XMLDocument")}}.</p>
<h2 id="Syntax">Syntax</h2>
<pre class="syntaxbox">
<em>doc</em> = document.implementation.createDocument(<em>namespaceURI</em>, <em>qualifiedNameStr</em>, <em>documentType</em>);</pre>
<h3>Parameters</h3>
<dl>
  <dt>
    <em>namespaceURI</em></dt>
  <dd>
    Is a {{domxref("DOMString")}} containing the namespace URI&nbsp;of the document to be created, or <code>null</code> if the document doesn't belong to one.</dd>
</dl>
<dl>
  <dt>
    <em>qualifiedNameStr </em></dt>
  <dd>
    Is a {{domxref("DOMString")}} containing the qualified name, that is an optional prefix and colon plus the local root element name, of the document to be created.</dd>
</dl>
<dl>
  <dt>
    <em>documentType</em></dt>
  <dd>
    Is the <a class="internal" href="/En/DOM/DocumentType" title="En/DOM/DocumentType"><code>DocumentType</code></a> of the document to be created.</dd>
</dl>
<ul>
</ul>
<h2 id="Example">Example</h2>
<pre class="brush: js">
var doc = document.implementation.createDocument ('http://www.w3.org/1999/xhtml', 'html', null);
var body = document.createElementNS('http://www.w3.org/1999/xhtml', 'body');
body.setAttribute('id', 'abc');
doc.documentElement.appendChild(body);
alert(doc.getElementById('abc')); // [object HTMLBodyElement]
</pre>
<h2 id="Specifications">Specifications</h2>
<table class="standard-table">
  <tbody>
    <tr>
      <th scope="col">Specification</th>
      <th scope="col">Status</th>
      <th scope="col">Comment</th>
    </tr>
    <tr>
      <td>{{SpecName('DOM WHATWG', '#dom-domimplementation-createdocument', 'DOMImplementation.createDocument')}}</td>
      <td>{{Spec2('DOM WHATWG')}}</td>
      <td>Modified the return type of <code>createDocument()</code> from {{domxref("Document")}} to {{domxref("XMLDocument")}}.</td>
    </tr>
    <tr>
      <td>{{SpecName('DOM3 Core', 'core.html#Level-2-Core-DOM-createDocument', 'DOMImplementation.createDocument')}}</td>
      <td>{{Spec2('DOM3 Core')}}</td>
      <td>No change from {{SpecName("DOM2 Core")}}</td>
    </tr>
    <tr>
      <td>{{SpecName('DOM2 Core', 'core.html#Level-2-Core-DOM-createDocument', 'DOMImplementation.createDocument')}}</td>
      <td>{{Spec2('DOM2 Core')}}</td>
      <td>Initial definition.</td>
    </tr>
  </tbody>
</table>
<h2 id="Browser_compatibility">Browser compatibility</h2>
<p>{{CompatibilityTable}}</p>
<div id="compat-desktop">
  <table class="compat-table">
    <tbody>
      <tr>
        <th>Feature</th>
        <th>Chrome</th>
        <th>Firefox (Gecko)</th>
        <th>Internet Explorer</th>
        <th>Opera</th>
        <th>Safari</th>
      </tr>
      <tr>
        <td>Basic support</td>
        <td>{{CompatVersionUnknown}}</td>
        <td>{{CompatGeckoDesktop("1.0")}}</td>
        <td>9.0</td>
        <td>{{CompatVersionUnknown}}</td>
        <td>{{CompatVersionUnknown}}</td>
      </tr>
    </tbody>
  </table>
</div>
<div id="compat-mobile">
  <table class="compat-table">
    <tbody>
      <tr>
        <th>Feature</th>
        <th>Android</th>
        <th>Firefox Mobile (Gecko)</th>
        <th>IE Mobile</th>
        <th>Opera Mobile</th>
        <th>Safari Mobile</th>
      </tr>
      <tr>
        <td>Basic support</td>
        <td>{{CompatVersionUnknown}}</td>
        <td>{{CompatGeckoMobile("1.0")}}</td>
        <td>{{CompatVersionUnknown}}</td>
        <td>{{CompatVersionUnknown}}</td>
        <td>{{CompatVersionUnknown}}</td>
      </tr>
    </tbody>
  </table>
</div>
<h2 id="See_also">See also</h2>
<ul>
  <li>The {{domxref("DOMImplementation")}} interface it belongs to.</li>
</ul>
Revert to this revision