Overview.html
author Art Barstow <art.barstow@nokia.com>
Sat, 16 Feb 2013 09:49:26 -0500
changeset 1059 6e1f307907ad
parent 1058 d5037c95c2ac
permissions -rw-r--r--
Change scheme of W3C stylesheet to https
     1 <!DOCTYPE html><html lang="en-US"><head>
     2   <meta charset="UTF-8">
     3   <title>DOM4</title>
     4   <link href="https://www.w3.org/StyleSheets/TR/W3C-WD" rel="stylesheet">
     5  </head>
     6  <body>
     7 
     8 <div class="head">
     9  
    10 <!--begin-logo-->
    11 <p><a href="http://www.w3.org/"><img alt="W3C" height="48" src="http://www.w3.org/Icons/w3c_home" width="72"></a></p>
    12 <!--end-logo-->
    13  <h1>DOM4</h1>
    14  <h2 class="no-num no-toc" id="w3c-working-draft-6-december-2012">W3C Working Draft 6 December 2012</h2>
    15 
    16  <dl>
    17   <dt>This Version:
    18   <dd><!--begin-link--><a href="http://www.w3.org/TR/2012/WD-dom-20121206/">http://www.w3.org/TR/2012/WD-dom-20121206/</a><!--end-link-->
    19   <dt>Latest Version:
    20   <dd><!--begin-link--><a href="http://www.w3.org/TR/dom/">http://www.w3.org/TR/dom/</a><!--end-link-->
    21   <dt>Previous Versions:
    22   <dd><!--begin-link--><a href="http://www.w3.org/TR/2012/WD-dom-20120405/">http://www.w3.org/TR/2012/WD-dom-20120405/</a><!--end-link-->
    23   <dd><!--begin-link--><a href="http://www.w3.org/TR/2012/WD-dom-20120105/">http://www.w3.org/TR/2012/WD-dom-20120105/</a><!--end-link-->
    24   <dd><!--begin-link--><a href="http://www.w3.org/TR/2011/WD-dom-20110915/">http://www.w3.org/TR/2011/WD-dom-20110915/</a><!--end-link--> 
    25   <dd><!--begin-link--><a href="http://www.w3.org/TR/2011/WD-domcore-20110531/">http://www.w3.org/TR/2011/WD-domcore-20110531/</a><!--end-link-->
    26   <dd><!--begin-link--><a href="http://www.w3.org/TR/2010/WD-domcore-20101007/">http://www.w3.org/TR/2010/WD-domcore-20101007/</a><!--end-link-->
    27   <dt>Living Standard:
    28   <dd><!--begin-link--><a href="http://dom.spec.whatwg.org/">http://dom.spec.whatwg.org/</a><!--end-link-->
    29   <dt>Latest Editor's Draft
    30   <dd><!--begin-link--><a href="http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html">http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html</a><!--end-link-->
    31 
    32   <dt>Participate:</dt>
    33   <dd>Send feedback to
    34   <a href="mailto:www-dom@w3.org?subject=%5Bdom%5D%20">www-dom@w3.org</a> (<a href="http://lists.w3.org/Archives/Public/www-dom/">archives</a>) or
    35   <a href="https://www.w3.org/Bugs/Public/enter_bug.cgi?product=WebAppsWG&amp;component=DOM">file a bug</a>
    36   (<a href="https://www.w3.org/Bugs/Public/buglist.cgi?product=WebAppsWG&amp;component=DOM&amp;resolution=---">open bugs</a>)
    37   <dd><a href="http://wiki.whatwg.org/wiki/IRC">IRC: #whatwg on Freenode</a>
    38 
    39   <dt>Version History:
    40   <dd><!--begin-link--><a href="http://dvcs.w3.org/hg/domcore/">http://dvcs.w3.org/hg/domcore/</a><!--end-link--></dd>
    41   <dd><a href="https://twitter.com/thedomstandard">@thedomstandard</a>
    42 
    43   <dt>Editors:
    44   <dd><a href="http://annevankesteren.nl/">Anne van Kesteren</a>
    45     &lt;<a href="mailto:annevk@annevk.nl">annevk@annevk.nl</a>&gt;
    46   <dd>Aryeh Gregor
    47    (<a href="http://www.mozilla.org/">Mozilla Foundation</a>)
    48    &lt;<a href="mailto:ayg@aryeh.name">ayg@aryeh.name</a>&gt;
    49   <dd><a href="http://lachy.id.au/">Lachlan Hunt</a>
    50     &lt;<a href="mailto:lachlan.hunt@lachy.id.au">lachlan.hunt@lachy.id.au</a>&gt;
    51   <dd>Ms2ger (<a href="http://www.mozilla.org/">Mozilla Foundation</a>)
    52     &lt;<a href="mailto:ms2ger@gmail.com">ms2ger@gmail.com</a>&gt;
    53  </dl>
    54 
    55 <p>This specification is based on <a href="http://dom.spec.whatwg.org/">DOM Standard</a> published by the
    56 <a href="http://www.whatwg.org/"><abbr title="Web Hypertext Application Technology Working Group">WHATWG</abbr></a>.
    57 <cite>DOM Standard</cite> is licensed under <a href="http://creativecommons.org/publicdomain/zero/1.0/" title="Creative Commons — CC0 1.0 Universal">Creative Commons CC0 1.0</a>
    58 (Public Domain Dedication).</p>
    59 
    60 
    61 <!--begin-copyright-->
    62 <p class="copyright"><a href="http://www.w3.org/Consortium/Legal/ipr-notice#Copyright">Copyright</a> © 2012 <a href="http://www.w3.org/"><abbr title="World Wide Web Consortium">W3C</abbr></a><sup>®</sup> (<a href="http://www.csail.mit.edu/"><abbr title="Massachusetts Institute of Technology">MIT</abbr></a>, <a href="http://www.ercim.eu/"><abbr title="European Research Consortium for Informatics and Mathematics">ERCIM</abbr></a>, <a href="http://www.keio.ac.jp/">Keio</a>), All Rights Reserved. W3C <a href="http://www.w3.org/Consortium/Legal/ipr-notice#Legal_Disclaimer">liability</a>, <a href="http://www.w3.org/Consortium/Legal/ipr-notice#W3C_Trademarks">trademark</a> and <a href="http://www.w3.org/Consortium/Legal/copyright-documents">document use</a> rules apply.</p>
    63 <!--end-copyright-->
    64 
    65 <hr>
    66 
    67 </div>
    68 
    69 
    70 <h2 class="no-num no-toc" id="abstract">Abstract</h2>
    71 <p>DOM defines the event and document model the Web platform uses. The
    72 DOM is a language- and platform neutral interface that allows programs and
    73 scripts to dynamically access and update the content and structure of
    74 documents.
    75 
    76 <h2 class="no-num no-toc" id="sotd">Status of this Document</h2>
    77 
    78 <p><em>This section describes the status of this document at the time of its
    79 publication. Other documents may supersede this document. A list of current
    80 W3C publications and the latest revision of this technical report can be
    81 found in the <a href="http://www.w3.org/TR/">W3C technical reports index</a>
    82 at http://www.w3.org/TR/.</em></p>
    83 
    84 <p>This is the 6 December 2012 W3C Working Draft of DOM4. The W3C Membership
    85 and other interested parties are invited to review the document and send
    86 comments to <a href="mailto:public-webapps@w3.org">public-webapps@w3.org</a>
    87 (<a href="http://lists.w3.org/Archives/Public/public-webapps/">public archive</a>)
    88 or to <a href="mailto:www-dom@w3.org">www-dom@w3.org</a>
    89 (<a href="http://lists.w3.org/Archives/Public/www-dom/">public archive</a>).</p>
    90 
    91 <p>Implementors should be aware that this specification is not stable.
    92 <strong>Implementors who are not taking part in the discussions are likely
    93 to find the specification changing out from under them in incompatible
    94 ways.</strong> Vendors interested in implementing this specification
    95 before it eventually reaches the Candidate Recommendation stage should
    96 join the aforementioned mailing lists and take part in the discussions.
    97 
    98 <p>This document is published by the <a href="http://www.w3.org/2008/webapps/">Web Applications Working Group</a>
    99 in co-operation with the <a href="http://www.whatwg.org/">Web Hypertext Application Technology Working Group</a>.
   100 The Working Group expects to advance this Working Draft to Recommendation Status.</p>
   101 
   102 <p>Publication as a Working Draft does not imply endorsement by the W3C
   103 Membership. This is a draft document and may be updated, replaced or
   104 obsoleted by other documents at any time. It is inappropriate to cite this
   105 document as other than work in progress.</p>
   106 
   107 <p>This document was produced by a group operating under the
   108 <a href="http://www.w3.org/Consortium/Patent-Policy-20040205/">5 February 2004 W3C Patent Policy</a>.
   109 W3C maintains a <a href="http://www.w3.org/2004/01/pp-impl/42538/status" rel="disclosure">public list of any patent disclosures</a>
   110 made in connection with the deliverables of the group; that page also
   111 includes instructions for disclosing a patent. An individual who has
   112 actual knowledge of a patent which the individual believes contains
   113 <a href="http://www.w3.org/Consortium/Patent-Policy-20040205/#def-essential">Essential Claim(s)</a>
   114 must disclose the information in accordance with
   115 <a href="http://www.w3.org/Consortium/Patent-Policy-20040205/#sec-Disclosure">section 6 of the W3C Patent Policy</a>.
   116 
   117 <h2 class="no-num no-toc" id="table-of-contents">Table of Contents</h2>
   118 
   119 <!--begin-toc-->
   120 <ol class="toc">
   121  <li><a class="no-num" href="#goals">Goals</a></li>
   122  <li><a href="#conformance"><span class="secno">1 </span>Conformance</a>
   123   <ol>
   124    <li><a href="#dependencies"><span class="secno">1.1 </span>Dependencies</a></li>
   125    <li><a href="#extensibility"><span class="secno">1.2 </span>Extensibility</a></ol></li>
   126  <li><a href="#terminology"><span class="secno">2 </span>Terminology</a>
   127   <ol>
   128    <li><a href="#trees"><span class="secno">2.1 </span>Trees</a></li>
   129    <li><a href="#strings"><span class="secno">2.2 </span>Strings</a></li>
   130    <li><a href="#common-microsyntaxes"><span class="secno">2.3 </span>Common microsyntaxes</a>
   131     <ol>
   132      <li><a href="#common-parser-idioms"><span class="secno">2.3.1 </span>Common parser idioms</a></li>
   133      <li><a href="#space-separated-tokens"><span class="secno">2.3.2 </span>Space-separated tokens</a></ol></li>
   134    <li><a href="#namespaces"><span class="secno">2.4 </span>Namespaces</a></ol></li>
   135  <li><a href="#errors"><span class="secno">3 </span>Errors</a>
   136   <ol>
   137    <li><a href="#exception-domexception"><span class="secno">3.1 </span>Exception <code>DOMException</code></a></li>
   138    <li><a href="#interface-domerror"><span class="secno">3.2 </span>Interface <code>DOMError</code></a></li>
   139    <li><a href="#error-names-0"><span class="secno">3.3 </span>Error names</a></ol></li>
   140  <li><a href="#events"><span class="secno">4 </span>Events</a>
   141   <ol>
   142    <li><a href="#introduction-to-dom-events"><span class="secno">4.1 </span>Introduction to "DOM Events"</a></li>
   143    <li><a href="#interface-event"><span class="secno">4.2 </span>Interface <code>Event</code></a></li>
   144    <li><a href="#interface-customevent"><span class="secno">4.3 </span>Interface <code>CustomEvent</code></a></li>
   145    <li><a href="#constructing-events"><span class="secno">4.4 </span>Constructing events</a></li>
   146    <li><a href="#interface-eventtarget"><span class="secno">4.5 </span>Interface <code>EventTarget</code></a></li>
   147    <li><a href="#dispatching-events"><span class="secno">4.6 </span>Dispatching events</a></li>
   148    <li><a href="#firing-events"><span class="secno">4.7 </span>Firing events</a></ol></li>
   149  <li><a href="#nodes"><span class="secno">5 </span>Nodes</a>
   150   <ol>
   151    <li><a href="#introduction-to-the-dom"><span class="secno">5.1 </span>Introduction to "The DOM"</a></li>
   152    <li><a href="#node-tree"><span class="secno">5.2 </span>Node tree</a>
   153     <ol>
   154      <li><a href="#mutation-algorithms"><span class="secno">5.2.1 </span>Mutation algorithms</a></li>
   155      <li><a href="#mutation-methods"><span class="secno">5.2.2 </span>Mutation methods</a></li>
   156      <li><a href="#legacy-mutation-methods"><span class="secno">5.2.3 </span>Legacy mutation methods</a></ol></li>
   157    <li><a href="#mutation-observers"><span class="secno">5.3 </span>Mutation observers</a>
   158     <ol>
   159      <li><a href="#interface-mutationobserver"><span class="secno">5.3.1 </span>Interface <code>MutationObserver</code></a></li>
   160      <li><a href="#queuing-a-mutation-record"><span class="secno">5.3.2 </span>Queuing a mutation record</a></li>
   161      <li><a href="#interface-mutationrecord"><span class="secno">5.3.3 </span>Interface <code>MutationRecord</code></a></li>
   162      <li><a href="#garbage-collection"><span class="secno">5.3.4 </span>Garbage collection</a></ol></li>
   163    <li><a href="#interface-node"><span class="secno">5.4 </span>Interface <code>Node</code></a></li>
   164    <li><a href="#interface-document"><span class="secno">5.5 </span>Interface <code>Document</code></a>
   165     <ol>
   166      <li><a href="#interface-domimplementation"><span class="secno">5.5.1 </span>Interface <code>DOMImplementation</code></a></ol></li>
   167    <li><a href="#interface-documentfragment"><span class="secno">5.6 </span>Interface <code>DocumentFragment</code></a></li>
   168    <li><a href="#interface-documenttype"><span class="secno">5.7 </span>Interface <code>DocumentType</code></a></li>
   169    <li><a href="#interface-element"><span class="secno">5.8 </span>Interface <code>Element</code></a>
   170     <ol>
   171      <li><a href="#interface-attr"><span class="secno">5.8.1 </span>Interface <code>Attr</code></a></ol></li>
   172    <li><a href="#interface-characterdata"><span class="secno">5.9 </span>Interface <code>CharacterData</code></a></li>
   173    <li><a href="#interface-text"><span class="secno">5.10 </span>Interface <code>Text</code></a></li>
   174    <li><a href="#interface-processinginstruction"><span class="secno">5.11 </span>Interface <code>ProcessingInstruction</code></a></li>
   175    <li><a href="#interface-comment"><span class="secno">5.12 </span>Interface <code>Comment</code></a></ol></li>
   176  <li><a href="#ranges"><span class="secno">6 </span>Ranges</a>
   177   <ol>
   178    <li><a href="#interface-range"><span class="secno">6.1 </span>Interface <code>Range</code></a></ol></li>
   179  <li><a href="#traversal"><span class="secno">7 </span>Traversal</a>
   180   <ol>
   181    <li><a href="#interface-nodeiterator"><span class="secno">7.1 </span>Interface <code>NodeIterator</code></a></li>
   182    <li><a href="#interface-treewalker"><span class="secno">7.2 </span>Interface <code>TreeWalker</code></a></li>
   183    <li><a href="#interface-nodefilter"><span class="secno">7.3 </span>Interface <code>NodeFilter</code></a></ol></li>
   184  <li><a href="#collections"><span class="secno">8 </span>Collections</a>
   185   <ol>
   186    <li><a href="#interface-nodelist"><span class="secno">8.1 </span>Interface <code>NodeList</code></a></li>
   187    <li><a href="#interface-htmlcollection"><span class="secno">8.2 </span>Interface <code>HTMLCollection</code></a></ol></li>
   188  <li><a href="#lists"><span class="secno">9 </span>Lists</a>
   189   <ol>
   190    <li><a href="#interface-domstringlist"><span class="secno">9.1 </span>Interface <code>DOMStringList</code></a></li>
   191    <li><a href="#interface-domtokenlist"><span class="secno">9.2 </span>Interface <code>DOMTokenList</code></a></li>
   192    <li><a href="#interface-domsettabletokenlist"><span class="secno">9.3 </span>Interface <code>DOMSettableTokenList</code></a></ol></li>
   193  <li><a href="#historical"><span class="secno">10 </span>Historical</a>
   194   <ol>
   195    <li><a href="#dom-events"><span class="secno">10.1 </span>DOM Events</a></li>
   196    <li><a href="#dom-core"><span class="secno">10.2 </span>DOM Core</a></li>
   197    <li><a href="#dom-range"><span class="secno">10.3 </span>DOM Range</a></li>
   198    <li><a href="#dom-traversal"><span class="secno">10.4 </span>DOM Traversal</a></ol></li>
   199  <li><a class="no-num" href="#references">References</a></li>
   200  <li><a class="no-num" href="#acknowledgments">Acknowledgments</a></ol>
   201 <!--end-toc-->
   202 
   203 
   204 
   205 <h2 class="no-num" id="goals">Goals</h2>
   206 
   207 <p>This specification standardizes the DOM. It does so as follows:</p>
   208 
   209 <ol>
   210  <li>
   211   <p>By consolidating <cite>DOM Level 3 Core</cite>
   212   <a class="informative" href="#refsDOM3CORE">[DOM3CORE]</a>,
   213   <cite>Element Traversal</cite>
   214   <a class="informative" href="#refsELEMENTTRAVERSAL">[ELEMENTTRAVERSAL]</a>, the
   215   "DOM Event Architecture" and "Basic Event Interfaces" chapters of
   216   <cite>DOM Level 3 Events</cite>
   217   <a class="informative" href="#refsDOM3EVENTS">[DOM3EVENTS]</a> (specific type
   218   of events do not belong in the base specification), and
   219   <cite>DOM Level 2 Traversal and Range</cite>
   220   <a class="informative" href="#refsDOM2TR">[DOM2TR]</a>, and:
   221 
   222   <ul>
   223    <li>Aligning them with the needs of ECMAScript where possible.
   224    <li>Aligning them with existing implementations.
   225    <li>Simplifying them as much as possible.
   226   </ul>
   227 
   228  <li><p>By moving features from HTML5 that ought to be part of the DOM
   229  platform here, while preventing a dependency on HTML5.
   230  <a class="informative" href="#refsHTML">[HTML]</a>
   231 
   232  <li>
   233   <p>By defining a replacement for the "Mutation Events" and
   234   "Mutation Name Event Types" chapters of <cite>DOM Level 3 Events</cite>
   235   <a class="informative" href="#refsDOM3EVENTS">[DOM3EVENTS]</a> as the old model
   236   was problematic.
   237 
   238   <p class="note">The old model is expected to be removed from implementations
   239   in due course.
   240 
   241  <li><p>By defining new features that simplify common DOM operations.
   242 </ol>
   243 
   244 
   245 
   246 <h2 id="conformance"><span class="secno">1 </span>Conformance</h2>
   247 <p>All diagrams, examples, and notes in this specification are
   248 non-normative, as are all sections explicitly marked non-normative.
   249 Everything else in this specification is normative.
   250 
   251 <p>The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT",
   252 "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and
   253 "OPTIONAL" in this document are to be interpreted as described in RFC 2119.
   254 For readability, these words do not appear in all uppercase letters in this
   255 specification. <a href="#refsRFC2119">[RFC2119]</a>
   256 
   257 <p>Requirements phrased in the imperative as part of algorithms
   258 (such as "strip any leading space characters" or "return false and
   259 terminate these steps") are to be interpreted with the meaning of the
   260 key word ("must", "should", "may", etc) used in introducing the
   261 algorithm.
   262 
   263 <p>Conformance requirements phrased as algorithms or specific steps
   264 may be implemented in any manner, so long as the end result is
   265 equivalent. (In particular, the algorithms defined in this
   266 specification are intended to be easy to follow, and not intended to
   267 be performant.)
   268 
   269 <p id="hardwareLimitations">User agents may impose
   270 implementation-specific limits on otherwise unconstrained inputs,
   271 e.g. to prevent denial of service attacks, to guard against running
   272 out of memory, or to work around platform-specific limitations.
   273 
   274 <p>When a method or an attribute is said to call another method or attribute, the user agent must invoke its internal API for that attribute or method so that e.g. the author can't change the behavior by overriding attributes or methods with custom properties or functions in ECMAScript.
   275 
   276 <p>Unless otherwise stated, string comparisons are done in a <a href="#case-sensitive">case-sensitive</a> manner.
   277 
   278 <h3 id="dependencies"><span class="secno">1.1 </span>Dependencies</h3>
   279 
   280 <p>The IDL fragments in this specification must be interpreted as
   281 required for conforming IDL fragments, as described in the Web IDL
   282 specification. <a href="#refsWEBIDL">[WEBIDL]</a>
   283 
   284 <p>Some of the terms used in this specification are defined in
   285 <cite>Encoding</cite>, <cite>Web IDL</cite>, <cite>XML</cite>, and
   286 <cite>Namespaces in XML</cite>.
   287 <a href="#refsENCODING">[ENCODING]</a>
   288 <a href="#refsWEBIDL">[WEBIDL]</a>
   289 <a href="#refsXML">[XML]</a>
   290 <a href="#refsXMLNS">[XMLNS]</a>
   291 
   292 <h3 id="extensibility"><span class="secno">1.2 </span>Extensibility</h3>
   293 
   294 <p>Vendor-specific proprietary extensions to this specification are
   295 strongly discouraged. Authors must not use such extensions, as
   296 doing so reduces interoperability and fragments the user base,
   297 allowing only users of specific user agents to access the content in
   298 question.
   299 
   300 <p>If vendor-specific extensions are needed, the members should be
   301 prefixed by vendor-specific strings to prevent clashes with future
   302 versions of this specification. Extensions must be defined so that
   303 the use of extensions neither contradicts nor causes the
   304 non-conformance of functionality defined in the specification.
   305 <!-- thanks to QA Framework -->
   306 
   307 <p>When vendor-neutral extensions to this specification are needed,
   308 either this specification can be updated accordingly, or an
   309 extension specification can be written that overrides the
   310 requirements in this specification. When someone applying this
   311 specification to their activities decides that they will recognize
   312 the requirements of such an extension specification, it becomes an
   313 <dfn id="other-applicable-specifications" title="other applicable specifications">applicable
   314 specification</dfn> for the purposes of conformance requirements in
   315 this specification.
   316 <!-- http://www.w3.org/mid/17E341CD-E790-422C-9F9A-69347EE01CEB@iki.fi -->
   317 
   318 
   319 <h2 id="terminology"><span class="secno">2 </span>Terminology</h2>
   320 
   321 <p>The term <dfn id="context-object">context object</dfn> means the object on which the method
   322 or attribute being discussed was called. When the
   323 <a href="#context-object">context object</a> is unambiguous, the term can be omitted.
   324 
   325 <!-- XXX we should prolly explain that "set attribute X to Y" works even for
   326 readonly attributes when it is language for implementors -->
   327 
   328 <h3 id="trees"><span class="secno">2.1 </span>Trees</h3> <!-- Sorry reddit, this is not /r/trees -->
   329 
   330 <p>Just like most programming paradigms the Web platform has finite
   331 hierarchical tree structures, simply named
   332 <dfn id="concept-tree" title="concept-tree">trees</dfn>. The
   333 <dfn id="concept-tree-order" title="concept-tree-order">tree order</dfn> is preorder, depth-first
   334 traversal.
   335 <!-- http://en.wikipedia.org/wiki/Tree_traversal#Depth-first_Traversal -->
   336 
   337 <p>An object that <dfn id="concept-tree-participate" title="concept-tree-participate">participates</dfn> in
   338 a <a href="#concept-tree" title="concept-tree">tree</a> has a
   339 <dfn id="concept-tree-parent" title="concept-tree-parent">parent</dfn>, which is either another object
   340 or null, and an ordered list of zero or more
   341 <dfn id="concept-tree-child" title="concept-tree-child">child</dfn> objects.
   342 
   343 <p>The <dfn id="concept-tree-root" title="concept-tree-root">root</dfn> of an object is itself, if it
   344 has no <a href="#concept-tree-parent" title="concept-tree-parent">parent</a>, or else it is the
   345 <a href="#concept-tree-root" title="concept-tree-root">root</a> of its
   346 <a href="#concept-tree-parent" title="concept-tree-parent">parent</a>.
   347 
   348 <p>An object <var title="">A</var> is called a
   349 <dfn id="concept-tree-descendant" title="concept-tree-descendant">descendant</dfn> of an object
   350 <var title="">B</var>, if either <var title="">A</var> is a
   351 <a href="#concept-tree-child" title="concept-tree-child">child</a> of <var title="">B</var> or
   352 <var title="">A</var> is a <a href="#concept-tree-child" title="concept-tree-child">child</a> of an
   353 object <var title="">C</var> that is a
   354 <a href="#concept-tree-descendant" title="concept-tree-descendant">descendant</a> of <var title="">B</var>.
   355 
   356 <p>An
   357 <dfn id="concept-tree-inclusive-descendant" title="concept-tree-inclusive-descendant">inclusive descendant</dfn> is
   358 an object or one of its
   359 <a href="#concept-tree-descendant" title="concept-tree-descendant">descendants</a>.
   360 
   361 <p>An object <var title="">A</var> is called an
   362 <dfn id="concept-tree-ancestor" title="concept-tree-ancestor">ancestor</dfn> of an object
   363 <var title="">B</var> if and only if <var title="">B</var> is a
   364 <a href="#concept-tree-descendant" title="concept-tree-descendant">descendant</a> of
   365 <var title="">A</var>.
   366 
   367 <p>An <dfn id="concept-tree-inclusive-ancestor" title="concept-tree-inclusive-ancestor">inclusive ancestor</dfn> is
   368 an object or one of its <a href="#concept-tree-ancestor" title="concept-tree-ancestor">ancestors</a>.
   369 
   370 <p>An object <var title="">A</var> is called a
   371 <dfn id="concept-tree-sibling" title="concept-tree-sibling">sibling</dfn> of an object
   372 <var title="">B</var>, if and only if <var title="">B</var> and <var title="">A</var>
   373 share the same non-null <a href="#concept-tree-parent" title="concept-tree-parent">parent</a>.
   374 
   375 <p>An object <var title="">A</var> is
   376 <dfn id="concept-tree-preceding" title="concept-tree-preceding">preceding</dfn> an object
   377 <var title="">B</var> if <var title="">A</var> and <var title="">B</var> are in the
   378 same <a href="#concept-tree" title="concept-tree">tree</a> and <var title="">A</var> comes
   379 before <var title="">B</var> in
   380 <a href="#concept-tree-order" title="concept-tree-order">tree order</a>.
   381 
   382 <p>An object <var title="">A</var> is
   383 <dfn id="concept-tree-following" title="concept-tree-following">following</dfn> an object
   384 <var title="">B</var> if <var title="">A</var> and <var title="">B</var> are in the
   385 same <a href="#concept-tree" title="concept-tree">tree</a> and <var title="">A</var> comes
   386 after <var title="">B</var> in
   387 <a href="#concept-tree-order" title="concept-tree-order">tree order</a>.
   388 
   389 <p>The <dfn id="concept-tree-first-child" title="concept-tree-first-child">first child</dfn> of an object is
   390 its first <a href="#concept-tree-child" title="concept-tree-child">child</a> or null if it has no
   391 <a href="#concept-tree-child" title="concept-tree-child">child</a>.
   392 
   393 <p>The <dfn id="concept-tree-last-child" title="concept-tree-last-child">last child</dfn> of an object is
   394 its last <a href="#concept-tree-child" title="concept-tree-child">child</a> or null if it has no
   395 <a href="#concept-tree-child" title="concept-tree-child">child</a>.
   396 
   397 <p>The <dfn id="concept-tree-previous-sibling" title="concept-tree-previous-sibling">previous sibling</dfn> of an
   398 object is its first <a href="#concept-tree-preceding" title="concept-tree-preceding">preceding</a>
   399 <a href="#concept-tree-sibling" title="concept-tree-sibling">sibling</a> or null if it has no
   400 <a href="#concept-tree-preceding" title="concept-tree-preceding">preceding</a>
   401 <a href="#concept-tree-sibling" title="concept-tree-sibling">sibling</a>.
   402 
   403 <p>The <dfn id="concept-tree-next-sibling" title="concept-tree-next-sibling">next sibling</dfn> of an
   404 object is its first <a href="#concept-tree-following" title="concept-tree-following">following</a>
   405 <a href="#concept-tree-sibling" title="concept-tree-sibling">sibling</a> or null if it has no
   406 <a href="#concept-tree-following" title="concept-tree-following">following</a>
   407 <a href="#concept-tree-sibling" title="concept-tree-sibling">sibling</a>.
   408 
   409 <p>The <dfn id="concept-tree-index" title="concept-tree-index">index</dfn> of an object is its number
   410 of <a href="#concept-tree-preceding" title="concept-tree-preceding">preceding</a>
   411 <a href="#concept-tree-sibling" title="concept-tree-sibling">siblings</a>.
   412 
   413 
   414 <h3 id="strings"><span class="secno">2.2 </span>Strings</h3>
   415 <p>Comparing two strings in a <dfn id="case-sensitive">case-sensitive</dfn> manner means comparing them exactly, code point for code point.
   416 
   417 <p>Comparing two strings in a <dfn id="ascii-case-insensitive">ASCII case-insensitive</dfn> manner means comparing them exactly, code point for code point, except that the characters in the range U+0041 .. U+005A (i.e. LATIN CAPITAL LETTER A to LATIN CAPITAL LETTER Z) and the corresponding characters in the range U+0061 .. U+007A (i.e. LATIN SMALL LETTER A to LATIN SMALL LETTER Z) are considered to also match.
   418 
   419 <p><dfn id="converted-to-ascii-uppercase" title="converted to ascii uppercase">Converting a string to ASCII uppercase</dfn> means replacing all characters in the range U+0061 to U+007A (i.e. LATIN SMALL LETTER A to LATIN SMALL LETTER Z) with the corresponding characters in the range U+0041 to U+005A (i.e. LATIN CAPITAL LETTER A to LATIN CAPITAL LETTER Z).
   420 
   421 <p><dfn id="converted-to-ascii-lowercase" title="converted to ascii lowercase">Converting a string to ASCII lowercase</dfn> means replacing all characters in the range U+0041 to U+005A (i.e. LATIN CAPITAL LETTER A to LATIN CAPITAL LETTER Z) with the corresponding characters in the range U+0061 to U+007A (i.e. LATIN SMALL LETTER A to LATIN SMALL LETTER Z).
   422 
   423 <p>A string <var title="">pattern</var> is a <dfn id="prefix-match">prefix match</dfn> for a string
   424 <var title="">s</var> when <var title="">pattern</var> is not longer than
   425 <var title="">s</var> and truncating <var title="">s</var> to
   426 <var title="">pattern</var>'s length leaves the two strings as matches of each
   427 other.
   428 
   429 <p>The <dfn id="space-character" title="space character">space characters</dfn>, for the
   430 purposes of this specification, are U+0020 SPACE, U+0009 CHARACTER
   431 TABULATION (tab), U+000A LINE FEED (LF), U+000C FORM FEED (FF), and
   432 U+000D CARRIAGE RETURN (CR).
   433 
   434 
   435 <h3 id="common-microsyntaxes"><span class="secno">2.3 </span>Common microsyntaxes</h3>
   436 <h4 id="common-parser-idioms"><span class="secno">2.3.1 </span>Common parser idioms</h4>
   437 <p>Some of the micro-parsers described below follow the pattern of having an
   438 <var title="">input</var> variable that holds the string being parsed, and having a
   439 <var title="">position</var> variable pointing at the next character to parse in
   440 <var title="">input</var>.
   441 
   442 <p>For parsers based on this pattern, a step that requires the user agent to
   443 <dfn id="collect-a-sequence-of-characters">collect a sequence of characters</dfn> means that the following algorithm
   444 must be run, with <var title="">characters</var> being the set of characters that
   445 can be collected:
   446 
   447 <ol>
   448  <li><p>Let <var title="">input</var> and <var title="">position</var> be the same
   449  variables as those of the same name in the algorithm that invoked these steps.
   450 
   451  <li><p>Let <var title="">result</var> be the empty string.
   452 
   453  <li><p>While <var title="">position</var> does not point past the end of
   454  <var title="">input</var> and the character at <var title="">position</var> is one of
   455  the <var title="">characters</var>, append that character to the end of
   456  <var title="">result</var> and advance <var title="">position</var> to the next
   457  character in <var title="">input</var>.
   458 
   459  <li><p>Return <var title="">result</var>.
   460 </ol>
   461 
   462 <p>The step <dfn id="skip-whitespace">skip whitespace</dfn> means that the user agent
   463 must <a href="#collect-a-sequence-of-characters">collect a sequence of characters</a> that are <a href="#space-character" title="space character">space characters</a>. The collected
   464 characters are not used.
   465 
   466 <h4 id="space-separated-tokens"><span class="secno">2.3.2 </span>Space-separated tokens</h4>
   467 
   468 <p>A <dfn id="set-of-space-separated-tokens">set of space-separated tokens</dfn> is a string containing
   469 zero or more words (known as tokens) separated by one or more <a href="#space-character" title="space character">space characters</a>, where words consist
   470 of any string of one or more characters, none of which are <a href="#space-character" title="space character">space characters</a>.
   471 
   472 <p>A string containing a <a href="#set-of-space-separated-tokens">set of space-separated tokens</a>
   473 may have leading or trailing <a href="#space-character" title="space character">space
   474 characters</a>.
   475 
   476 <p>An <dfn id="unordered-set-of-unique-space-separated-tokens">unordered set of unique space-separated tokens</dfn> is a
   477 <a href="#set-of-space-separated-tokens">set of space-separated tokens</a> where none of the tokens
   478 are duplicated.
   479 
   480 <p>An <dfn id="ordered-set-of-unique-space-separated-tokens">ordered set of unique space-separated tokens</dfn> is a
   481 <a href="#set-of-space-separated-tokens">set of space-separated tokens</a> where none of the tokens
   482 are duplicated but where the order of the tokens is meaningful.
   483 
   484 <p><a href="#set-of-space-separated-tokens" title="set of space-separated tokens">Sets of
   485 space-separated tokens</a> sometimes have a defined set of
   486 allowed values. When a set of allowed values is defined, the tokens
   487 must all be from that list of allowed values; other values are
   488 non-conforming. If no such set of allowed values is provided, then
   489 all values are conforming.
   490 
   491 <p class="note">How tokens in a <a href="#set-of-space-separated-tokens">set of space-separated
   492 tokens</a> are to be compared (e.g. case-sensitively or not) is
   493 defined on a per-set basis.
   494 
   495 <div class="impl">
   496 
   497 <p>When a user agent has to <dfn id="split-a-string-on-spaces">split a string on spaces</dfn>, it
   498 must use the following algorithm:
   499 
   500 <ol>
   501  <li><p>Let <var title="">input</var> be the string being parsed.
   502 
   503  <li><p>Let <var title="">position</var> be a pointer into <var title="">input</var>,
   504  initially pointing at the start of the string.
   505 
   506  <li><p>Let <var title="">tokens</var> be a list of tokens, initially empty.
   507 
   508  <li><p><a href="#skip-whitespace">Skip whitespace</a>.
   509 
   510  <li><p>While <var title="">position</var> is not past the end of
   511  <var title="">input</var>:
   512 
   513   <ol>
   514    <li><p><a href="#collect-a-sequence-of-characters">Collect a sequence of characters</a> that are not
   515    <a href="#space-character" title="space character">space characters</a>.
   516 
   517    <li><p>Add the string collected in the previous step to
   518    <var title="">tokens</var>.
   519 
   520    <li><p><a href="#skip-whitespace">Skip whitespace</a>.
   521   </ol>
   522 
   523  <li><p>Return <var title="">tokens</var>.
   524 </ol>
   525 
   526 <p>When a user agent has to <dfn id="remove-a-token-from-a-string">remove a token from a string</dfn>,
   527 it must use the following algorithm:
   528 
   529 <ol>
   530  <li><p>Let <var title="">input</var> be the string being modified.
   531 
   532  <li><p>Let <var title="">token</var> be the token being removed. It will not
   533  contain any <a href="#space-character" title="space character">space characters</a>.
   534 
   535  <li><p>Let <var title="">output</var> be the output string, initially empty.
   536 
   537  <li><p>Let <var title="">position</var> be a pointer into <var title="">input</var>,
   538  initially pointing at the start of the string.
   539 
   540  <li><p><i title="">Loop</i>: If <var title="">position</var> is beyond the end of
   541  <var title="">input</var>, terminate these steps.
   542 
   543  <li>
   544   <p>If the character at <var title="">position</var> is a <a href="#space-character">space
   545   character</a>:
   546 
   547   <ol>
   548    <li><p>Append the character at <var title="">position</var> to the end of <var title="">output</var>.
   549 
   550    <li><p>Advance <var title="">position</var> so it points at the next character
   551    in <var title="">input</var>.
   552 
   553    <li><p>Return to the step labeled <i title="">loop</i>.
   554   </ol>
   555 
   556  <li><p>Otherwise, the character at <var title="">position</var> is the first
   557  character of a token. <a href="#collect-a-sequence-of-characters">Collect a sequence of characters</a> that are
   558  not <a href="#space-character" title="space character">space characters</a>, and let that be <var title="">s</var>.
   559 
   560  <li>
   561   <p>If <var title="">s</var> is exactly equal to <var title="">token</var>, then:
   562 
   563   <ol>
   564    <li><p><a href="#skip-whitespace">Skip whitespace</a> (in <var title="">input</var>).
   565 
   566    <li><p>Remove any <a href="#space-character" title="space character">space characters</a>
   567    currently at the end of <var title="">output</var>.
   568 
   569    <li><p>If <var title="">position</var> is not past the end of <var title="">input</var>, and <var title="">output</var> is not the empty string,
   570    append a single U+0020 SPACE character at the end of <var title="">output</var>.
   571   </ol>
   572 
   573  <li><p>Otherwise, append <var title="">s</var> to the end of <var title="">output</var>.
   574 
   575  <li><p>Return to the step labeled <i title="">loop</i>.
   576 </ol>
   577 
   578 <p class="note">This causes any occurrences of the token to be
   579 removed from the string, and any spaces that were surrounding the
   580 token to be collapsed to a single space, except at the start and end
   581 of the string, where such spaces are removed.
   582 
   583 </div>
   584 
   585 
   586 <h3 id="namespaces"><span class="secno">2.4 </span>Namespaces</h3>
   587 <p>The <dfn id="html-namespace">HTML namespace</dfn> is <code title="">http://www.w3.org/1999/xhtml</code>.
   588 
   589 <p>The <dfn id="xml-namespace">XML namespace</dfn> is <code title="">http://www.w3.org/XML/1998/namespace</code>.
   590 
   591 <p>The <dfn id="xmlns-namespace">XMLNS namespace</dfn> is <code title="">http://www.w3.org/2000/xmlns/</code>.
   592 
   593 
   594 <h2 id="errors"><span class="secno">3 </span>Errors</h2>
   595 <h3 id="exception-domexception"><span class="secno">3.1 </span>Exception <code><a href="#domexception">DOMException</a></code></h3>
   596 <pre class="idl">exception <dfn id="domexception">DOMException</dfn> {
   597   const unsigned short <a href="#dom-domexception-index_size_err" title="dom-DOMException-INDEX_SIZE_ERR">INDEX_SIZE_ERR</a> = 1;
   598   const unsigned short <span title="dom-DOMException-DOMSTRING_SIZE_ERR">DOMSTRING_SIZE_ERR</span> = 2; // historical
   599   const unsigned short <a href="#dom-domexception-hierarchy_request_err" title="dom-DOMException-HIERARCHY_REQUEST_ERR">HIERARCHY_REQUEST_ERR</a> = 3;
   600   const unsigned short <a href="#dom-domexception-wrong_document_err" title="dom-DOMException-WRONG_DOCUMENT_ERR">WRONG_DOCUMENT_ERR</a> = 4;
   601   const unsigned short <a href="#dom-domexception-invalid_character_err" title="dom-DOMException-INVALID_CHARACTER_ERR">INVALID_CHARACTER_ERR</a> = 5;
   602   const unsigned short <span title="dom-DOMException-NO_DATA_ALLOWED_ERR">NO_DATA_ALLOWED_ERR</span> = 6; // historical
   603   const unsigned short <a href="#dom-domexception-no_modification_allowed_err" title="dom-DOMException-NO_MODIFICATION_ALLOWED_ERR">NO_MODIFICATION_ALLOWED_ERR</a> = 7;
   604   const unsigned short <a href="#dom-domexception-not_found_err" title="dom-DOMException-NOT_FOUND_ERR">NOT_FOUND_ERR</a> = 8;
   605   const unsigned short <a href="#dom-domexception-not_supported_err" title="dom-DOMException-NOT_SUPPORTED_ERR">NOT_SUPPORTED_ERR</a> = 9;
   606   const unsigned short <span title="dom-DOMException-INUSE_ATTRIBUTE_ERR">INUSE_ATTRIBUTE_ERR</span> = 10; // historical
   607   const unsigned short <a href="#dom-domexception-invalid_state_err" title="dom-DOMException-INVALID_STATE_ERR">INVALID_STATE_ERR</a> = 11;
   608   const unsigned short <a href="#dom-domexception-syntax_err" title="dom-DOMException-SYNTAX_ERR">SYNTAX_ERR</a> = 12;
   609   const unsigned short <a href="#dom-domexception-invalid_modification_err" title="dom-DOMException-INVALID_MODIFICATION_ERR">INVALID_MODIFICATION_ERR</a> = 13;
   610   const unsigned short <a href="#dom-domexception-namespace_err" title="dom-DOMException-NAMESPACE_ERR">NAMESPACE_ERR</a> = 14;
   611   const unsigned short <a href="#dom-domexception-invalid_access_err" title="dom-DOMException-INVALID_ACCESS_ERR">INVALID_ACCESS_ERR</a> = 15;
   612   const unsigned short <span title="dom-DOMException-VALIDATION_ERR">VALIDATION_ERR</span> = 16; // historical
   613   const unsigned short <span title="dom-DOMException-TYPE_MISMATCH_ERR">TYPE_MISMATCH_ERR</span> = 17; // historical; use TypeError instead
   614   const unsigned short <a href="#dom-domexception-security_err" title="dom-DOMException-SECURITY_ERR">SECURITY_ERR</a> = 18;
   615   const unsigned short <a href="#dom-domexception-network_err" title="dom-DOMException-NETWORK_ERR">NETWORK_ERR</a> = 19;
   616   const unsigned short <a href="#dom-domexception-abort_err" title="dom-DOMException-ABORT_ERR">ABORT_ERR</a> = 20;
   617   const unsigned short <a href="#dom-domexception-url_mismatch_err" title="dom-DOMException-URL_MISMATCH_ERR">URL_MISMATCH_ERR</a> = 21;
   618   const unsigned short <a href="#dom-domexception-quota_exceeded_err" title="dom-DOMException-QUOTA_EXCEEDED_ERR">QUOTA_EXCEEDED_ERR</a> = 22;
   619   const unsigned short <a href="#dom-domexception-timeout_err" title="dom-DOMException-TIMEOUT_ERR">TIMEOUT_ERR</a> = 23;
   620   const unsigned short <a href="#dom-domexception-invalid_node_type_err" title="dom-DOMException-INVALID_NODE_TYPE_ERR">INVALID_NODE_TYPE_ERR</a> = 24;
   621   const unsigned short <a href="#dom-domexception-data_clone_err" title="dom-DOMException-DATA_CLONE_ERR">DATA_CLONE_ERR</a> = 25;
   622   unsigned short <a href="#dom-domexception-code" title="dom-DOMException-code">code</a>;
   623 };</pre>
   624 
   625 <p>The <dfn id="dom-domexception-code" title="dom-DOMException-code"><code>code</code></dfn> exception
   626 field must return the value it was initialized to. When an exception is
   627 created it must be initialized to zero.
   628 
   629 <p>To <dfn id="concept-throw" title="concept-throw">throw</dfn> a <var title="">name</var> exception
   630 these steps must be run:
   631 
   632 <ol>
   633  <li><p>Create a new <code><a href="#domexception">DOMException</a></code> exception whose
   634  <a class="external" data-anolis-spec="webidl" href="http://dev.w3.org/2006/webapi/WebIDL/#dfn-exception-name">name</a> is <var title="">name</var>.
   635 
   636  <li><p>Set its <a class="external" data-anolis-spec="webidl" href="http://dev.w3.org/2006/webapi/WebIDL/#dfn-exception-message">message</a> to a
   637  user agent-defined value.
   638 
   639  <li><p>If its <a class="external" data-anolis-spec="webidl" href="http://dev.w3.org/2006/webapi/WebIDL/#dfn-exception-name">name</a> is in the first
   640  column of the <a href="#error-names-table">error names table</a> and has a corresponding legacy
   641  <code title="dom-DOMException-code"><a href="#dom-domexception-code">code</a></code> exception field value in the
   642  third column, set its <code title="dom-DOMException-code"><a href="#dom-domexception-code">code</a></code>
   643  exception field to that value.
   644 
   645  <li><p><a class="external" data-anolis-spec="webidl" href="http://dev.w3.org/2006/webapi/WebIDL/#dfn-throw">Throw</a> the exception.
   646 </ol>
   647 
   648 <p class="example">To
   649 <i title="">throw a "<code><a href="#timeouterror">TimeoutError</a></code>" exception</i>, a
   650 user agent would construct a <code><a href="#domexception">DOMException</a></code> exception whose
   651 <a class="external" data-anolis-spec="webidl" href="http://dev.w3.org/2006/webapi/WebIDL/#dfn-exception-name">name</a> is
   652 "<code><a href="#timeouterror">TimeoutError</a></code>" and
   653 <code title="dom-DOMException-code"><a href="#dom-domexception-code">code</a></code> exception field value is 23,
   654 and actually throw that object as an exception. In JavaScript, this
   655 exception will have a <code title="">name</code> property whose value is
   656 "<code><a href="#timeouterror">TimeoutError</a></code>".
   657 
   658 
   659 <h3 id="interface-domerror"><span class="secno">3.2 </span>Interface <code><a href="#domerror">DOMError</a></code></h3>
   660 
   661 <p class="note">This interface is intended for other specifications that want
   662 to introduce error handling through other means than exceptions. As with
   663 exceptions, the <a href="#error-names-table">error names table</a> is used.
   664 
   665 <pre class="idl">interface <dfn id="domerror">DOMError</dfn> {
   666   readonly attribute DOMString <a href="#dom-domerror-name" title="dom-DOMError-name">name</a>;
   667 };</pre>
   668 
   669 <p>The <dfn id="dom-domerror-name" title="dom-DOMError-name"><code>name</code></dfn> attribute must
   670 return the value it was initialized to.
   671 
   672 <p>A
   673 <dfn id="concept-domerror" title="concept-DOMError"><var title="">name</var> <code>DOMError</code></dfn>
   674 means a <code><a href="#domerror">DOMError</a></code> object whose
   675 <code title="dom-DOMError-name"><a href="#dom-domerror-name">name</a></code> attribute is initialized to
   676 <var title="">name</var>.
   677 
   678 <p class="example">A specification could say that an <code title="">error</code>
   679 attribute must return a
   680 <a href="#concept-domerror" title="concept-DOMError">"<code>SyntaxError</code>" <code>DOMError</code></a>.
   681 
   682 
   683 <h3 id="error-names-0"><span class="secno">3.3 </span>Error names</h3>
   684 
   685 <p>The <dfn id="error-names-table">error names table</dfn> below lists all the allowed error names,
   686 a description, and legacy <code title="dom-DOMException-code"><a href="#dom-domexception-code">code</a></code>
   687 exception field values (when the error name is used for
   688 <a href="#concept-throw" title="concept-throw">throwing</a> an exception).
   689 
   690 <p class="note">If an error name is not listed here, please file a bug as
   691 indicated at the top of this specification and it will be addressed shortly.
   692 Thanks!
   693 
   694 <table id="error-names">
   695  <thead>
   696  <tr><th>Name<th>Description<th>Legacy <code title="dom-DOMException-code"><a href="#dom-domexception-code">code</a></code> exception field value (if any)
   697  <tbody>
   698  <tr>
   699   <td>"<dfn id="indexsizeerror"><code>IndexSizeError</code></dfn>"
   700   <td>The index is not in the allowed range.
   701   <td><dfn id="dom-domexception-index_size_err" title="dom-DOMException-INDEX_SIZE_ERR"><code>INDEX_SIZE_ERR</code></dfn> (1)
   702  <tr>
   703   <td>"<dfn id="hierarchyrequesterror"><code>HierarchyRequestError</code></dfn>"
   704   <td>The operation would yield an incorrect <a href="#node-tree">node tree</a>.
   705   <td><dfn id="dom-domexception-hierarchy_request_err" title="dom-DOMException-HIERARCHY_REQUEST_ERR"><code>HIERARCHY_REQUEST_ERR</code></dfn> (3)
   706  <tr>
   707   <td>"<dfn id="wrongdocumenterror"><code>WrongDocumentError</code></dfn>"
   708   <td>The object is in the wrong <a href="#concept-document" title="concept-document">document</a>.
   709   <td><dfn id="dom-domexception-wrong_document_err" title="dom-DOMException-WRONG_DOCUMENT_ERR"><code>WRONG_DOCUMENT_ERR</code></dfn> (4)
   710  <tr>
   711   <td>"<dfn id="invalidcharactererror"><code>InvalidCharacterError</code></dfn>"
   712   <td>The string contains invalid characters.
   713   <td><dfn id="dom-domexception-invalid_character_err" title="dom-DOMException-INVALID_CHARACTER_ERR"><code>INVALID_CHARACTER_ERR</code></dfn> (5)
   714  <tr>
   715   <td>"<dfn id="nomodificationallowederror"><code>NoModificationAllowedError</code></dfn>"
   716   <td>The object can not be modified.
   717   <td><dfn id="dom-domexception-no_modification_allowed_err" title="dom-DOMException-NO_MODIFICATION_ALLOWED_ERR"><code>NO_MODIFICATION_ALLOWED_ERR</code></dfn> (7)
   718  <tr>
   719   <td>"<dfn id="notfounderror"><code>NotFoundError</code></dfn>"
   720   <td>The object can not be found here.
   721   <td><dfn id="dom-domexception-not_found_err" title="dom-DOMException-NOT_FOUND_ERR"><code>NOT_FOUND_ERR</code></dfn> (8)
   722  <tr>
   723   <td>"<dfn id="notsupportederror"><code>NotSupportedError</code></dfn>"
   724   <td>The operation is not supported.
   725   <td><dfn id="dom-domexception-not_supported_err" title="dom-DOMException-NOT_SUPPORTED_ERR"><code>NOT_SUPPORTED_ERR</code></dfn> (9)
   726  <tr>
   727   <td>"<dfn id="invalidstateerror"><code>InvalidStateError</code></dfn>"
   728   <td>The object is in an invalid state.
   729   <td><dfn id="dom-domexception-invalid_state_err" title="dom-DOMException-INVALID_STATE_ERR"><code>INVALID_STATE_ERR</code></dfn> (11)
   730  <tr>
   731   <td>"<dfn id="syntaxerror"><code>SyntaxError</code></dfn>"
   732   <td>The string did not match the expected pattern.
   733   <td><dfn id="dom-domexception-syntax_err" title="dom-DOMException-SYNTAX_ERR"><code>SYNTAX_ERR</code></dfn> (12)
   734  <tr>
   735   <td>"<dfn id="invalidmodificationerror"><code>InvalidModificationError</code></dfn>"
   736   <td>The object can not be modified in this way.
   737   <td><dfn id="dom-domexception-invalid_modification_err" title="dom-DOMException-INVALID_MODIFICATION_ERR"><code>INVALID_MODIFICATION_ERR</code></dfn> (13)
   738  <tr>
   739   <td>"<dfn id="namespaceerror"><code>NamespaceError</code></dfn>"
   740   <td>The operation is not allowed by <cite>Namespaces in XML</cite>. <a href="#refsXMLNS">[XMLNS]</a>
   741   <td><dfn id="dom-domexception-namespace_err" title="dom-DOMException-NAMESPACE_ERR"><code>NAMESPACE_ERR</code></dfn> (14)
   742  <tr>
   743   <td>"<dfn id="invalidaccesserror"><code>InvalidAccessError</code></dfn>"
   744   <td>The object does not support the operation or argument.
   745   <td><dfn id="dom-domexception-invalid_access_err" title="dom-DOMException-INVALID_ACCESS_ERR"><code>INVALID_ACCESS_ERR</code></dfn> (15)
   746  <tr>
   747   <!-- XHR -->
   748   <td>"<dfn id="securityerror"><code>SecurityError</code></dfn>"
   749   <td>The operation is insecure.
   750   <td><dfn id="dom-domexception-security_err" title="dom-DOMException-SECURITY_ERR"><code>SECURITY_ERR</code></dfn> (18)
   751  <tr>
   752   <!-- XHR -->
   753   <td>"<dfn id="networkerror"><code>NetworkError</code></dfn>"
   754   <td>A network error occurred.
   755   <td><dfn id="dom-domexception-network_err" title="dom-DOMException-NETWORK_ERR"><code>NETWORK_ERR</code></dfn> (19)
   756  <tr>
   757   <!-- XHR -->
   758   <td>"<dfn id="aborterror"><code>AbortError</code></dfn>"
   759   <td>The operation was aborted.
   760   <td><dfn id="dom-domexception-abort_err" title="dom-DOMException-ABORT_ERR"><code>ABORT_ERR</code></dfn> (20)
   761  <tr>
   762   <!-- Workers -->
   763   <td>"<dfn id="urlmismatcherror"><code>URLMismatchError</code></dfn>"
   764   <td>The given URL does not match another URL.
   765   <td><dfn id="dom-domexception-url_mismatch_err" title="dom-DOMException-URL_MISMATCH_ERR"><code>URL_MISMATCH_ERR</code></dfn> (21)
   766  <tr>
   767   <!-- HTML -->
   768   <td>"<dfn id="quotaexceedederror"><code>QuotaExceededError</code></dfn>"
   769   <td>The quota has been exceeded.
   770   <td><dfn id="dom-domexception-quota_exceeded_err" title="dom-DOMException-QUOTA_EXCEEDED_ERR"><code>QUOTA_EXCEEDED_ERR</code></dfn> (22)
   771  <tr>
   772   <!-- XHR -->
   773   <td>"<dfn id="timeouterror"><code>TimeoutError</code></dfn>"
   774   <td>The operation timed out.
   775   <td><dfn id="dom-domexception-timeout_err" title="dom-DOMException-TIMEOUT_ERR"><code>TIMEOUT_ERR</code></dfn> (23)
   776  <tr>
   777   <td>"<dfn id="invalidnodetypeerror"><code>InvalidNodeTypeError</code></dfn>"
   778   <td>The supplied node is incorrect or has an incorrect ancestor for this operation.
   779   <td><dfn id="dom-domexception-invalid_node_type_err" title="dom-DOMException-INVALID_NODE_TYPE_ERR"><code>INVALID_NODE_TYPE_ERR</code></dfn> (24)
   780  <tr>
   781   <!-- HTML -->
   782   <td>"<dfn id="datacloneerror"><code>DataCloneError</code></dfn>"
   783   <td>The object can not be cloned.
   784   <td><dfn id="dom-domexception-data_clone_err" title="dom-DOMException-DATA_CLONE_ERR"><code>DATA_CLONE_ERR</code></dfn> (25)
   785  <tr>
   786   <td>"<dfn id="encodingerror"><code>EncodingError</code></dfn>"
   787   <td>The encoding operation (either encoded or decoding) failed.
   788   <td>—
   789 </table>
   790 
   791 
   792 
   793 <h2 id="events"><span class="secno">4 </span>Events</h2>
   794 
   795 <h3 id="introduction-to-dom-events"><span class="secno">4.1 </span>Introduction to "DOM Events"</h3>
   796 
   797 <p>Throughout the web platform <a href="#concept-event" title="concept-event">events</a> are
   798 <a href="#concept-event-dispatch" title="concept-event-dispatch">dispatched</a> to objects to signal an
   799 occurrence, such as network activity or user interaction. These objects
   800 implement the <code><a href="#eventtarget">EventTarget</a></code> interface and can therefore add
   801 <a href="#concept-event-listener" title="concept-event-listener">event listeners</a> to observe
   802 <a href="#concept-event" title="concept-event">events</a>:
   803 
   804 <pre><code>obj.addEventListener("load", imgFetched)
   805 
   806 function imgFetched(ev) {
   807   // great success
   808
   809 }</code></pre>
   810 
   811 <p><a href="#concept-event-listener" title="concept-event-listener">Event listeners</a> can be removed
   812 by utilizing the
   813 <code title="dom-EventTarget-removeEventListener"><a href="#dom-eventtarget-removeeventlistener">removeEventListener()</a></code>
   814 method, passing the same arguments.
   815 
   816 <p><a href="#concept-event" title="concept-event">Events</a> are objects too and implement the
   817 <code><a href="#event">Event</a></code> interface (or a derived interface). In the example above
   818 <var title="">ev</var> is the <a href="#concept-event" title="concept-event">event</a>. It is
   819 passed as argument to
   820 <a href="#concept-event-listener" title="concept-event-listener">event listener</a>'s <b>callback</b>
   821 (typically a JavaScript Function as shown above).
   822 <a href="#concept-event-listener" title="concept-event-listener">Event listeners</a> key off the
   823 <a href="#concept-event" title="concept-event">event</a>'s
   824 <code title="dom-Event-type"><a href="#dom-event-type">type</a></code> attribute value
   825 ("<code title="">load</code>" in the above example). The
   826 <a href="#concept-event" title="concept-event">event</a>'s
   827 <code title="dom-Event-target"><a href="#dom-event-target">target</a></code> attribute value returns the
   828 object to which the <a href="#concept-event" title="concept-event">event</a> was
   829 <a href="#concept-event-dispatch" title="concept-event-dispatch">dispatched</a> (<var title="">obj</var>
   830 above).
   831 
   832 <p>Now while typically <a href="#concept-event" title="concept-event">events</a> are
   833 <a href="#concept-event-dispatch" title="concept-event-dispatch">dispatched</a> by the user agent as
   834 the result of user interaction or the completion of some task, applications
   835 can <a href="#concept-event-dispatch" title="concept-event-dispatch">dispatch</a>
   836 <a href="#concept-event" title="concept-event">events</a> themselves, commonly known as
   837 synthetic events:
   838 
   839 <pre><code>// add an appropriate event listener
   840 obj.addEventListener("cat", function(e) { process(e.detail) })
   841 
   842 // create and dispatch the event
   843 var event = new CustomEvent("cat", {"detail":{"hazcheeseburger":true}})
   844 obj.dispatchEvent(event)</code></pre>
   845 
   846 <p>Apart from signaling, <a href="#concept-event" title="concept-event">events</a> are
   847 sometimes also used to let an application control what happens next in an
   848 operation. For instance as part of form submission an
   849 <a href="#concept-event" title="concept-event">event</a> whose
   850 <code title="dom-Event-type"><a href="#dom-event-type">type</a></code> attribute value is
   851 "<code title="">submit</code>" is
   852 <a href="#concept-event-dispatch" title="concept-event-dispatch">dispatched</a>. If this
   853 <a href="#concept-event" title="concept-event">event</a>'s
   854 <code title="dom-Event-preventDefault"><a href="#dom-event-preventdefault">preventDefault()</a></code> method is
   855 invoked, form submission will be terminated. Applications who wish to make
   856 use of this functionality through <a href="#concept-event" title="concept-event">events</a>
   857 <a href="#concept-event-dispatch" title="concept-event-dispatch">dispatched</a> by the application
   858 (synthetic events) can make use of the return value of the
   859 <code title="dom-EventTarget-dispatchEvent"><a href="#dom-eventtarget-dispatchevent">dispatchEvent()</a></code> method:
   860 
   861 <pre><code>if(obj.dispatchEvent(event)) {
   862   // event was not canceled, time for some magic
   863
   864 }</code></pre>
   865 
   866 <p>When an <a href="#concept-event" title="concept-event">event</a> is
   867 <a href="#concept-event-dispatch" title="concept-event-dispatch">dispatched</a> to an object that
   868 <a href="#concept-tree-participate" title="concept-tree-participate">participates</a> in a
   869 <a href="#concept-tree" title="concept-tree">tree</a> (e.g. an
   870 <a href="#concept-element" title="concept-element">element</a>), it can reach
   871 <a href="#concept-event-listener" title="concept-event-listener">event listeners</a> on that object's
   872 <a href="#concept-tree-ancestor" title="concept-tree-ancestor">ancestors</a> too. First all object's
   873 <a href="#concept-tree-ancestor" title="concept-tree-ancestor">ancestor</a>
   874 <a href="#concept-event-listener" title="concept-event-listener">event listeners</a> whose
   875 <b>capture</b> variable is set to true are invoked, in
   876 <a href="#concept-tree-order" title="concept-tree-order">tree order</a>. Second, object's own
   877 <a href="#concept-event-listener" title="concept-event-listener">event listeners</a> are invoked. And
   878 finally, and only if <a href="#concept-event" title="concept-event">event</a>'s
   879 <a href="#dom-event-bubbles" title="dom-Event-bubbles">bubbles</a> attribute value is true,
   880 object's  <a href="#concept-tree-ancestor" title="concept-tree-ancestor">ancestor</a>
   881 <a href="#concept-event-listener" title="concept-event-listener">event listeners</a> are invoked again,
   882 but now in reverse <a href="#concept-tree-order" title="concept-tree-order">tree order</a>.
   883 
   884 <p>Lets look at an example on how <a href="#concept-event" title="concept-event">events</a>
   885 work in a <a href="#concept-tree" title="concept-tree">tree</a>:
   886 
   887 <pre><code>&lt;!doctype html&gt;
   888 &lt;html&gt;
   889  &lt;head&gt;
   890   &lt;title&gt;Boring example&lt;/title&gt;
   891  &lt;/head&gt;
   892  &lt;body&gt;
   893   &lt;p&gt;Hello &lt;span id=x&gt;world&lt;/span&gt;!&lt;/p&gt;
   894   &lt;script&gt;
   895    function test(e) {
   896      debug(e.target, e.currentTarget, e.eventPhase)
   897    }
   898    document.addEventListener("hey", test, true)
   899    document.body.addEventListener("hey", test)
   900    var ev = new Event("hey", {bubbles:true})
   901    document.getElementById("x").dispatchEvent(ev)
   902   &lt;/script&gt;
   903  &lt;/body&gt;
   904 &lt;/html&gt;</code></pre>
   905 
   906 <p>The <code title="">debug</code> function will be invoked twice. Each time
   907 the <a href="#concept-event" title="concept-event">events</a>'s
   908 <code title="dom-Event-target"><a href="#dom-event-target">target</a></code> attribute value will be the
   909 <code title="">span</code> <a href="#concept-element" title="concept-element">element</a>. The
   910 first time <code title="dom-Event-target"><a href="#dom-event-target">currentTarget</a></code> attribute's
   911 value will be the <a href="#concept-document" title="concept-document">document</a>, the second
   912 time the <code title="">body</code> <a href="#concept-element" title="concept-element">element</a>.
   913 <code title="dom-Event-eventPhase"><a href="#dom-event-eventphase">eventPhase</a></code> attribute's value
   914 switches from <code title="dom-Event-CAPTURING_PHASE"><a href="#dom-event-capturing_phase">CAPTURING_PHASE</a></code>
   915 to <code title="dom-Event-BUBBLING_PHASE"><a href="#dom-event-bubbling_phase">BUBBLING_PHASE</a></code>. If an
   916 <a href="#concept-event-listener" title="concept-event-listener">event listener</a> was registered for
   917 the <code title="">span</code> <a href="#concept-element" title="concept-element">element</a>,
   918 <code title="dom-Event-eventPhase"><a href="#dom-event-eventphase">eventPhase</a></code> attribute's value
   919 would have been <code title="dom-Event-AT_TARGET"><a href="#dom-event-at_target">AT_TARGET</a></code>.
   920 
   921 
   922 <h3 id="interface-event"><span class="secno">4.2 </span>Interface <code><a href="#event">Event</a></code></h3>
   923 
   924 <pre class="idl">[Constructor(DOMString <var title="">type</var>, optional <a href="#eventinit">EventInit</a> <var title="">eventInitDict</var>)]
   925 interface <dfn id="event">Event</dfn> {
   926   readonly attribute DOMString <a href="#dom-event-type" title="dom-Event-type">type</a>;
   927   readonly attribute <a href="#eventtarget">EventTarget</a>? <a href="#dom-event-target" title="dom-Event-target">target</a>;
   928   readonly attribute <a href="#eventtarget">EventTarget</a>? <a href="#dom-event-currenttarget" title="dom-Event-currentTarget">currentTarget</a>;
   929 
   930   const unsigned short <a href="#dom-event-none" title="dom-Event-NONE">NONE</a> = 0;
   931   const unsigned short <a href="#dom-event-capturing_phase" title="dom-Event-CAPTURING_PHASE">CAPTURING_PHASE</a> = 1;
   932   const unsigned short <a href="#dom-event-at_target" title="dom-Event-AT_TARGET">AT_TARGET</a> = 2;
   933   const unsigned short <a href="#dom-event-bubbling_phase" title="dom-Event-BUBBLING_PHASE">BUBBLING_PHASE</a> = 3;
   934   readonly attribute unsigned short <a href="#dom-event-eventphase" title="dom-Event-eventPhase">eventPhase</a>;
   935 
   936   void <a href="#dom-event-stoppropagation" title="dom-Event-stopPropagation">stopPropagation</a>();
   937   void <a href="#dom-event-stopimmediatepropagation" title="dom-Event-stopImmediatePropagation">stopImmediatePropagation</a>();
   938 
   939   readonly attribute boolean <a href="#dom-event-bubbles" title="dom-Event-bubbles">bubbles</a>;
   940   readonly attribute boolean <a href="#dom-event-cancelable" title="dom-Event-cancelable">cancelable</a>;
   941   void <a href="#dom-event-preventdefault" title="dom-Event-preventDefault">preventDefault</a>();
   942   readonly attribute boolean <a href="#dom-event-defaultprevented" title="dom-Event-defaultPrevented">defaultPrevented</a>;
   943 
   944   readonly attribute boolean <a href="#dom-event-istrusted" title="dom-Event-isTrusted">isTrusted</a>;
   945   readonly attribute DOMTimeStamp <a href="#dom-event-timestamp" title="dom-Event-timeStamp">timeStamp</a>;
   946 
   947   void <a href="#dom-event-initevent" title="dom-Event-initEvent">initEvent</a>(DOMString <var title="">type</var>, boolean <var title="">bubbles</var>, boolean <var title="">cancelable</var>);
   948 };
   949 
   950 dictionary <dfn id="eventinit">EventInit</dfn> {
   951   boolean <span title="dom-EventInit-bubbles">bubbles</span>;
   952   boolean <span title="dom-EventInit-cancelable">cancelable</span>;
   953 };</pre>
   954 
   955 <p>An <dfn id="concept-event" title="concept-event">event</dfn> allows for signaling that
   956 something has occurred. E.g. that an image has completed downloading. It is
   957 represented by the <code><a href="#event">Event</a></code> interface or an interface that
   958 inherits from the <code><a href="#event">Event</a></code> interface.</p>
   959 
   960 <dl class="domintro">
   961  <dt><code>var <var title="">event</var> = new Event(<var title="">type</var> [, <var title="">eventInitDict</var>])</code>
   962  <dd><p>Returns a new <var title="">event</var> whose
   963  <code title="dom-Event-type"><a href="#dom-event-type">type</a></code> attribute value is set to
   964  <var title="">type</var>. The optional <var title="">eventInitDict</var> argument
   965  allows for setting the <code title="dom-Event-bubbles"><a href="#dom-event-bubbles">bubbles</a></code> and
   966  <code title="dom-Event-cancelable"><a href="#dom-event-cancelable">cancelable</a></code> attributes via object
   967  members of the same name.
   968 
   969  <dt><code><var title="">event</var> . <a href="#dom-event-type" title="dom-Event-type">type</a></code>
   970  <dd><p>Returns the type of <var title="">event</var>, e.g.
   971  "<code title="">click</code>", "<code title="">hashchange</code>", or
   972  "<code title="">submit</code>".
   973 
   974  <dt><code><var title="">event</var> . <a href="#dom-event-target" title="dom-Event-target">target</a></code>
   975  <dd><p>Returns the object <var title="">event</var> is
   976  <a href="#concept-event-dispatch" title="concept-event-dispatch">dispatched</a> to.
   977 
   978  <dt><code><var title="">event</var> . <a href="#dom-event-currenttarget" title="dom-Event-currentTarget">currentTarget</a></code>
   979  <dd><p>Returns the object whose
   980  <a href="#concept-event-listener" title="concept-event-listener">event listener</a>'s <b>callback</b>
   981  is invoked.
   982 
   983  <dt><code><var title="">event</var> . <a href="#dom-event-eventphase" title="dom-Event-eventPhase">eventPhase</a></code>
   984  <dd><p>Returns the <a href="#concept-event" title="concept-event">event</a>'s phase, which is
   985  one of <code title="dom-Event-NONE"><a href="#dom-event-none">NONE</a></code>,
   986  <code title="dom-Event-CAPTURING_PHASE"><a href="#dom-event-capturing_phase">CAPTURING_PHASE</a></code>,
   987  <code title="dom-Event-AT_TARGET"><a href="#dom-event-at_target">AT_TARGET</a></code>, and
   988  <code title="dom-Event-BUBBLING_PHASE"><a href="#dom-event-bubbling_phase">BUBBLING_PHASE</a></code>.
   989 
   990  <dt><code><var title="">event</var> . <a href="#dom-event-stoppropagation" title="dom-Event-stopPropagation">stopPropagation</a>()</code>
   991  <dd><p>When <a href="#concept-event-dispatch" title="concept-event-dispatch">dispatched</a> in a
   992  <a href="#concept-tree" title="concept-tree">tree</a>, invoking this method prevents
   993  <var title="">event</var> from reaching any other objects than the current.
   994 
   995  <dt><code><var title="">event</var> . <a href="#dom-event-stopimmediatepropagation" title="dom-Event-stopImmediatePropagation">stopImmediatePropagation</a>()</code>
   996  <dd><p>Invoking this method prevents <var title="">event</var> from reaching
   997  any <a href="#concept-event-listener" title="concept-event-listener">event listeners</a> registered
   998  after the current one and when
   999  <a href="#concept-event-dispatch" title="concept-event-dispatch">dispatched</a> in a
  1000  <a href="#concept-tree" title="concept-tree">tree</a> also prevents
  1001  <var title="">event</var> from reaching any other objects.
  1002 
  1003  <dt><code><var title="">event</var> . <a href="#dom-event-bubbles" title="dom-Event-bubbles">bubbles</a></code>
  1004  <dd><p>Returns true if <var title="">event</var>'s goes through its <code title="dom-Event-target"><a href="#dom-event-target">target</a></code> attribute value's <a href="#concept-tree-ancestor" title="concept-tree-ancestor">ancestors</a> in reverse <a href="#concept-tree-order" title="concept-tree-order">tree order</a>, or false otherwise.
  1005 
  1006  <dt><code><var title="">event</var> . <a href="#dom-event-cancelable" title="dom-Event-cancelable">cancelable</a></code>
  1007  <dd><p>Returns true or false depending on how <var title="">event</var> was
  1008  initialized. Its return value does not always carry meaning, but true can
  1009  indicate that part of the operation during which <var title="">event</var> was
  1010  <a href="#concept-event-dispatch" title="concept-event-dispatch">dispatched</a>, can be canceled by
  1011  invoking the <code title="dom-Event-preventDefault"><a href="#dom-event-preventdefault">preventDefault()</a></code>
  1012  method.
  1013 
  1014  <dt><code><var title="">event</var> . <a href="#dom-event-preventdefault" title="dom-Event-preventDefault">preventDefault</a>()</code>
  1015  <dd><p>If invoked when the
  1016  <code title="dom-Event-cancelable"><a href="#dom-event-cancelable">cancelable</a></code> attribute value is true,
  1017  signals to the operation that caused <var title="">event</var> to be
  1018  <a href="#concept-event-dispatch" title="concept-event-dispatch">dispatched</a> that it needs to be
  1019  canceled.
  1020 
  1021  <dt><code><var title="">event</var> . <a href="#dom-event-defaultprevented" title="dom-Event-defaultPrevented">defaultPrevented</a></code>
  1022  <dd><p>Returns true if
  1023  <code title="dom-Event-preventDefault"><a href="#dom-event-preventdefault">preventDefault()</a></code> was invoked
  1024  while the <code title="dom-Event-cancelable"><a href="#dom-event-cancelable">cancelable</a></code> attribute
  1025  value is true, or false otherwise.
  1026 
  1027  <dt><code><var title="">event</var> . <a href="#dom-event-istrusted" title="dom-Event-isTrusted">isTrusted</a></code>
  1028  <dd><p>Returns true if <var title="">event</var> was
  1029  <a href="#concept-event-dispatch" title="concept-event-dispatch">dispatched</a> by the user agent, or
  1030  false otherwise.
  1031 
  1032  <dt><code><var title="">event</var> . <a href="#dom-event-timestamp" title="dom-Event-timeStamp">timeStamp</a></code>
  1033  <dd><p>Returns the creation time of <var title="">event</var> in the number of
  1034  milliseconds that passed since 00:00:00 UTC on 1 January 1970.
  1035 
  1036  <!-- initEvent is dead -->
  1037 </dl>
  1038 
  1039 <p>The <dfn id="dom-event-type" title="dom-Event-type"><code>type</code></dfn> attribute must
  1040 return the value it was initialized to. When an
  1041 <a href="#concept-event" title="concept-event">event</a> is created the attribute must be
  1042 initialized to the empty string.
  1043 
  1044 <p>The <dfn id="dom-event-target" title="dom-Event-target"><code>target</code></dfn> and
  1045 <dfn id="dom-event-currenttarget" title="dom-Event-currentTarget"><code>currentTarget</code></dfn>
  1046 attributes must return the values they were initialized to. When an
  1047 <a href="#concept-event" title="concept-event">event</a> is created the attributes must be
  1048 initialized to null.
  1049 
  1050 <p>The <dfn id="dom-event-eventphase" title="dom-Event-eventPhase"><code>eventPhase</code></dfn>
  1051 attribute must return the value it was initialized to, which must be one of
  1052 the following:</p>
  1053 <dl>
  1054  <dt><dfn id="dom-event-none" title="dom-Event-NONE"><code>NONE</code></dfn> (numeric value 0)
  1055  <dd><p><a href="#concept-event" title="concept-event">Events</a> not currently
  1056  <a href="#concept-event-dispatch" title="concept-event-dispatch">dispatched</a> are in this phase.
  1057  <dt><dfn id="dom-event-capturing_phase" title="dom-Event-CAPTURING_PHASE"><code>CAPTURING_PHASE</code></dfn> (numeric value 1)</dt>
  1058  <dd><p>When an <a href="#concept-event" title="concept-event">event</a> is
  1059  <a href="#concept-event-dispatch" title="concept-event-dispatch">dispatched</a> to an object that
  1060  <a href="#concept-tree-participate" title="concept-tree-participate">participates</a> in a
  1061  <a href="#concept-tree" title="concept-tree">tree</a> it will be in this phase before it
  1062  reaches its <code title="dom-Event-target"><a href="#dom-event-target">target</a></code> attribute value.
  1063  <dt><dfn id="dom-event-at_target" title="dom-Event-AT_TARGET"><code>AT_TARGET</code></dfn> (numeric value 2)
  1064  <dd><p>When an <a href="#concept-event" title="concept-event">event</a> is
  1065  <a href="#concept-event-dispatch" title="concept-event-dispatch">dispatched</a> it will be in this
  1066  phase on its <code title="dom-Event-target"><a href="#dom-event-target">target</a></code> attribute value.
  1067  <dt><dfn id="dom-event-bubbling_phase" title="dom-Event-BUBBLING_PHASE"><code>BUBBLING_PHASE</code></dfn> (numeric value 3)
  1068  <dd><p>When an <a href="#concept-event" title="concept-event">event</a> is
  1069  <a href="#concept-event-dispatch" title="concept-event-dispatch">dispatched</a> to an object that
  1070  <a href="#concept-tree-participate" title="concept-tree-participate">participates</a> in a
  1071  <a href="#concept-tree" title="concept-tree">tree</a> it will be in this phase after it
  1072  reaches its <code title="dom-Event-target"><a href="#dom-event-target">target</a></code> attribute value.
  1073 </dl>
  1074 <p>Initially the attribute must be initialized to
  1075 <code title="dom-Event-NONE"><a href="#dom-event-none">NONE</a></code>.
  1076 
  1077 <hr>
  1078 
  1079 <p>Each <a href="#concept-event" title="concept-event">event</a> has the following associated
  1080 flags that are all initially unset:</p>
  1081 <ul>
  1082  <li><dfn id="stop-propagation-flag">stop propagation flag</dfn>
  1083  <li><dfn id="stop-immediate-propagation-flag">stop immediate propagation flag</dfn>
  1084  <li><dfn id="canceled-flag">canceled flag</dfn>
  1085  <li><dfn id="initialized-flag">initialized flag</dfn>
  1086  <li><dfn id="dispatch-flag">dispatch flag</dfn>
  1087 </ul>
  1088 
  1089 <p>When the
  1090 <dfn id="dom-event-stoppropagation" title="dom-Event-stopPropagation"><code>stopPropagation()</code></dfn>
  1091 method is invoked the <a href="#stop-propagation-flag">stop propagation flag</a> must be set.
  1092 <p>When the
  1093 <dfn id="dom-event-stopimmediatepropagation" title="dom-Event-stopImmediatePropagation"><code>stopImmediatePropagation()</code></dfn>
  1094 method is invoked both the <a href="#stop-propagation-flag">stop propagation flag</a> and
  1095 <a href="#stop-immediate-propagation-flag">stop immediate propagation flag</a> must be set.
  1096 
  1097 <p>The <dfn id="dom-event-bubbles" title="dom-Event-bubbles"><code>bubbles</code></dfn> and
  1098 <dfn id="dom-event-cancelable" title="dom-Event-cancelable"><code>cancelable</code></dfn> attributes
  1099 must return the values they were initialized to. When an
  1100 <a href="#concept-event" title="concept-event">event</a> is created the attributes must be
  1101 initialized to false.
  1102 
  1103 <p>When the
  1104 <dfn id="dom-event-preventdefault" title="dom-Event-preventDefault"><code>preventDefault()</code></dfn>
  1105 method is invoked and the <code title="dom-Event-cancelable"><a href="#dom-event-cancelable">cancelable</a></code>
  1106 attribute is true, the <a href="#canceled-flag">canceled flag</a> must be set.
  1107 
  1108 <p>The <dfn id="dom-event-defaultprevented" title="dom-Event-defaultPrevented"><code>defaultPrevented</code></dfn>
  1109 attribute must return true if the <a href="#canceled-flag">canceled flag</a> is set and
  1110 false otherwise.
  1111 
  1112 <hr>
  1113 
  1114 <p>The <dfn id="dom-event-istrusted" title="dom-Event-isTrusted"><code>isTrusted</code></dfn> attribute
  1115 must return the value it was initialized to. When an
  1116 <a href="#concept-event" title="concept-event">event</a> is created the attribute must be
  1117 initialized to false.
  1118 
  1119 <p>The <dfn id="dom-event-timestamp" title="dom-Event-timeStamp"><code>timeStamp</code></dfn> attribute
  1120 must return the value it was initialized to. When an
  1121 <a href="#concept-event" title="concept-event">event</a> is created the attribute must be
  1122 initialized to the number of milliseconds that has passed since
  1123 00:00:00 UTC on 1 January 1970.
  1124 
  1125 <!-- XXX leap seconds?
  1126          http://krijnhoetmer.nl/irc-logs/whatwg/20110707#l-330 -->
  1127 
  1128 <hr>
  1129 
  1130 <p>When the <dfn id="dom-event-initevent" title="dom-Event-initEvent"><code>initEvent(<var title="">type</var>, <var title="">bubbles</var>, <var title="">cancelable</var>)</code></dfn>
  1131 method is invoked these steps must be run:</p>
  1132 
  1133 <ol>
  1134  <li><p>Set the <a href="#initialized-flag">initialized flag</a>.
  1135  <li><p>If the <a href="#dispatch-flag">dispatch flag</a> is set, terminate these steps.
  1136  <li><p>Unset the <a href="#stop-propagation-flag">stop propagation flag</a>,
  1137  <a href="#stop-immediate-propagation-flag">stop immediate propagation flag</a>, and
  1138  <a href="#canceled-flag">canceled flag</a>.
  1139  <li><p>Set the <code title="dom-Event-isTrusted"><a href="#dom-event-istrusted">isTrusted</a></code> attribute
  1140  to false.
  1141  <li><p>Set the <code title="dom-Event-target"><a href="#dom-event-target">target</a></code> attribute to
  1142  null.
  1143  <li><p>Set the <code title="dom-Event-type"><a href="#dom-event-type">type</a></code> attribute to the
  1144  <var title="">type</var> argument.
  1145  <li><p>Set the <code title="dom-Event-bubbles"><a href="#dom-event-bubbles">bubbles</a></code> attribute to
  1146  the <var title="">bubbles</var> argument.
  1147  <li><p>Set the <code title="dom-Event-cancelable"><a href="#dom-event-cancelable">cancelable</a></code> attribute
  1148  to the <var title="">cancelable</var> argument.
  1149 </ol>
  1150 
  1151 <p class="note">As <a href="#concept-event" title="concept-event">events</a> have constructors
  1152 <code title="dom-Event-initEvent"><a href="#dom-event-initevent">initEvent()</a></code> is superfluous. However,
  1153 it has to be supported for legacy content.
  1154 
  1155 
  1156 <h3 id="interface-customevent"><span class="secno">4.3 </span>Interface <code><a href="#customevent">CustomEvent</a></code></h3>
  1157 
  1158 <pre class="idl">[Constructor(DOMString <var title="">type</var>, optional <a href="#customeventinit">CustomEventInit</a> <var title="">eventInitDict</var>)]
  1159 interface <dfn id="customevent">CustomEvent</dfn> : <a href="#event">Event</a> {
  1160   readonly attribute any <a href="#dom-customevent-detail" title="dom-CustomEvent-detail">detail</a>;
  1161 };
  1162 
  1163 dictionary <dfn id="customeventinit">CustomEventInit</dfn> : <a href="#eventinit">EventInit</a> {
  1164   any <span title="dom-CustomEventInit-detail">detail</span>;
  1165 };</pre>
  1166 
  1167 <p><a href="#concept-event" title="concept-event">Events</a> using the
  1168 <code><a href="#customevent">CustomEvent</a></code> interface can be used to carry custom data.</p>
  1169 
  1170 <dl class="domintro">
  1171  <dt><code>var <var title="">event</var> = new CustomEvent(<var title="">type</var> [, <var title="">eventInitDict</var>])</code>
  1172  <dd><p>Works analogously to the constructor for <code><a href="#event">Event</a></code> except
  1173  that the optional <var title="">eventInitDict</var> argument now
  1174  allows for setting the <code title="dom-Event-detail">detail</code> attribute
  1175  too.
  1176 
  1177  <dt><code><var title="">event</var> . <a href="#dom-customevent-detail" title="dom-CustomEvent-detail">detail</a></code>
  1178  <dd><p>Returns any custom data <var title="">event</var> was created with.
  1179  Typically used for synthetic events.
  1180 </dl>
  1181 
  1182 <p>The <dfn id="dom-customevent-detail" title="dom-CustomEvent-detail"><code>detail</code></dfn> attribute
  1183 must return the value it was initialized to. When an
  1184 <a href="#concept-event" title="concept-event">event</a> is created the attribute must be
  1185 initialized to null.
  1186 
  1187 
  1188 <h3 id="constructing-events"><span class="secno">4.4 </span>Constructing events</h3>
  1189 
  1190 <p>When a constructor of the <code><a href="#event">Event</a></code> interface, or of an
  1191 interface that inherits from the <code><a href="#event">Event</a></code> interface, is invoked,
  1192 these steps must be run:
  1193 
  1194 <ol>
  1195  <li><p>Create an <a href="#concept-event" title="concept-event">event</a> that uses the
  1196  interface the constructor was invoked upon.
  1197 
  1198  <li><p>Set its <a href="#initialized-flag">initialized flag</a>.
  1199 
  1200  <li><p>Initialize the <code title="dom-Event-type"><a href="#dom-event-type">type</a></code> attribute to
  1201  the <var title="">type</var> argument.
  1202 
  1203  <li><p>If there is an <var title="">eventInitDict</var> argument then for each
  1204  <a class="external" data-anolis-spec="webidl" href="http://dev.w3.org/2006/webapi/WebIDL/#dfn-dictionary-member">dictionary member</a> defined therein find
  1205  the attribute on <a href="#concept-event" title="concept-event">event</a> whose
  1206  <a class="external" data-anolis-spec="webidl" href="http://dev.w3.org/2006/webapi/WebIDL/#dfn-identifier">identifier</a> matches the key of
  1207  the <a class="external" data-anolis-spec="webidl" href="http://dev.w3.org/2006/webapi/WebIDL/#dfn-dictionary-member">dictionary member</a> and then
  1208  set the attribute to the value of that
  1209  <a class="external" data-anolis-spec="webidl" href="http://dev.w3.org/2006/webapi/WebIDL/#dfn-dictionary-member">dictionary member</a>.
  1210 
  1211  <li><p>Return the <a href="#concept-event" title="concept-event">event</a>.
  1212 </ol>
  1213 
  1214 
  1215 <h3 id="interface-eventtarget"><span class="secno">4.5 </span>Interface <code><a href="#eventtarget">EventTarget</a></code></h3>
  1216 
  1217 <pre class="idl">interface <dfn id="eventtarget">EventTarget</dfn> {
  1218   void <a href="#dom-eventtarget-addeventlistener" title="dom-EventTarget-addEventListener">addEventListener</a>(DOMString <var title="">type</var>, <a href="#eventlistener">EventListener</a>? <var title="">callback</var>, optional boolean <var title="">capture</var> = false);
  1219   void <a href="#dom-eventtarget-removeeventlistener" title="dom-EventTarget-removeEventListener">removeEventListener</a>(DOMString <var title="">type</var>, <a href="#eventlistener">EventListener</a>? <var title="">callback</var>, optional boolean <var title="">capture</var> = false);
  1220   boolean <a href="#dom-eventtarget-dispatchevent" title="dom-EventTarget-dispatchEvent">dispatchEvent</a>(<a href="#event">Event</a> <var title="">event</var>);
  1221 };
  1222 
  1223 callback interface <dfn id="eventlistener">EventListener</dfn> {
  1224   void <span title="dom-EventListener-handleEvent">handleEvent</span>(<a href="#event">Event</a> <var title="">event</var>);
  1225 };</pre>
  1226 
  1227 <p><code><a href="#eventtarget">EventTarget</a></code> is an object to which an
  1228 <a href="#concept-event" title="concept-event">event</a> is
  1229 <a href="#concept-event-dispatch" title="concept-event-dispatch">dispatched</a> when something has
  1230 occurred. Each <code><a href="#eventtarget">EventTarget</a></code> has an associated list of
  1231 <a href="#concept-event-listener" title="concept-event-listener">event listeners</a>.
  1232 
  1233 <p>An <dfn id="concept-event-listener" title="concept-event-listener">event listener</dfn> associates a
  1234 callback with a specific <a href="#concept-event" title="concept-event">event</a>. Each
  1235 <a href="#concept-event-listener" title="concept-event-listener">event listener</a> consists of a
  1236 <b>type</b> (of the <a href="#concept-event" title="concept-event">event</a>),
  1237 <b>callback</b>, and <b>capture</b> variable.
  1238 
  1239 <p class="note">The <b>callback</b> is named <code><a href="#eventlistener">EventListener</a></code> for
  1240 historical reasons. As can be seen from the definition above, an
  1241 <a href="#concept-event-listener" title="concept-event-listener">event listener</a> is a more broad
  1242 concept.
  1243 
  1244 <dl class="domintro">
  1245  <dt><code><var title="">target</var> . <a href="#dom-eventtarget-addeventlistener" title="dom-EventTarget-addEventListener">addEventListener</a>(<var title="">type</var>, <var title="">callback</var> [, <var title="">capture</var> = false])</code>
  1246  <dd>
  1247   <p>Appends an <a href="#concept-event-listener" title="concept-event-listener">event listener</a>
  1248   for <a href="#concept-event" title="concept-event">events</a> whose
  1249   <code title="dom-Event-type"><a href="#dom-event-type">type</a></code> attribute value is
  1250   <var title="">type</var>. The <var title="">callback</var> argument sets the
  1251   <b>callback</b> that will be invoked when the
  1252   <a href="#concept-event" title="concept-event">event</a> is
  1253   <a href="#concept-event-dispatch" title="concept-event-dispatch">dispatched</a>. When set to true,
  1254   the <var title="">capture</var> argument ensures <b>callback</b> is only
  1255   invoked when the <a href="#concept-event" title="concept-event">event</a>'s
  1256   <code title="dom-Event-eventPhase"><a href="#dom-event-eventphase">eventPhase</a></code> attribute value is
  1257   <code title="dom-Event-CAPTURING_PHASE"><a href="#dom-event-capturing_phase">CAPTURING_PHASE</a></code>.
  1258 
  1259   <p>The <a href="#concept-event-listener" title="concept-event-listener">event listener</a> is
  1260   appended to <var title="">target</var>'s list of
  1261   <a href="#concept-event-listener" title="concept-event-listener">event listeners</a> and is not
  1262   appended if it is a duplicate (the
  1263   <a href="#concept-event-listener" title="concept-event-listener">event listeners</a> in the list are
  1264   unique).
  1265 
  1266  <dt><code><var title="">target</var> . <a href="#dom-eventtarget-removeeventlistener" title="dom-EventTarget-removeEventListener">removeEventListener</a>(<var title="">type</var>, <var title="">callback</var> [, <var title="">capture</var> = false])</code>
  1267  <dd><p>Remove the <a href="#concept-event-listener" title="concept-event-listener">event listener</a>
  1268  in <var title="">target</var>'s list of
  1269  <a href="#concept-event-listener" title="concept-event-listener">event listeners</a> with the same
  1270  <var title="">type</var>, <var title="">callback</var>, and
  1271  <var title="">capture</var>.
  1272 
  1273  <dt><code><var title="">target</var> . <a href="#dom-eventtarget-dispatchevent" title="dom-EventTarget-dispatchEvent">dispatchEvent</a>(<var title="">event</var>)</code>
  1274  <dd><p><a href="#concept-event-dispatch" title="concept-event-dispatch">Dispatches</a> a synthetic
  1275  event <var title="">event</var> to <var title="">target</var> and returns true
  1276  if either <var title="">event</var>'s
  1277  <code title="dom-Event-cancelable"><a href="#dom-event-cancelable">cancelable</a></code> attribute value is false
  1278  or it's <code title="dom-Event-preventDefault"><a href="#dom-event-preventdefault">preventDefault()</a></code> method
  1279  was not invoked, or false otherwise.
  1280 </dl>
  1281 
  1282 <p>When the
  1283 <dfn id="dom-eventtarget-addeventlistener" title="dom-EventTarget-addEventListener"><code>addEventListener(<var title="">type</var>, <var title="">callback</var>, <var title="">capture</var>)</code></dfn>
  1284 method is invoked these steps must be run:
  1285 <ol>
  1286  <li><p>If <var title="">callback</var> is null terminate these steps.
  1287  <li><p>Append an <a href="#concept-event-listener" title="concept-event-listener">event listener</a>
  1288  to the associated list of
  1289  <a href="#concept-event-listener" title="concept-event-listener">event listeners</a> with <b>type</b>
  1290  set to <var title="">type</var>, <b>callback</b> set to <var title="">callback</var>, and
  1291  <b>capture</b> set to <var title="">capture</var>, unless there
  1292  already is an <a href="#concept-event-listener" title="concept-event-listener">event listener</a> in
  1293  that list with the same <b>type</b>, <b>callback</b>, and <b>capture</b>.
  1294 </ol>
  1295 
  1296 <p>When the <dfn id="dom-eventtarget-removeeventlistener" title="dom-EventTarget-removeEventListener"><code>removeEventListener(<var title="">type</var>, <var title="">callback</var>, <var title="">capture</var>)</code></dfn> method is invoked these steps must be run:
  1297 <ol>
  1298  <li><p>Remove an <a href="#concept-event-listener" title="concept-event-listener">event listener</a>
  1299  from the associated list of
  1300  <a href="#concept-event-listener" title="concept-event-listener">event listeners</a>, whose
  1301  <b>type</b> is <var title="">name</var>, <b>callback</b> is <var title="">callback</var>, and
  1302  <b>capture</b> is <var title="">capture</var>.</p>
  1303 </ol>
  1304 
  1305 <p>When the
  1306 <dfn id="dom-eventtarget-dispatchevent" title="dom-EventTarget-dispatchEvent"><code>dispatchEvent(<var title="">event</var>)</code></dfn> method is invoked these steps must be run:
  1307 <ol>
  1308  <li><p>If <var title="">event</var>'s <a href="#dispatch-flag">dispatch flag</a> is set, or if
  1309  its <a href="#initialized-flag">initialized flag</a> is not set,
  1310  <a href="#concept-throw" title="concept-throw">throw</a> an
  1311  "<code><a href="#invalidstateerror">InvalidStateError</a></code>" exception and terminate these steps.
  1312  <li><p>Initialize <var title="">event</var>'s
  1313  <code title="dom-Event-isTrusted"><a href="#dom-event-istrusted">isTrusted</a></code> attribute to false.
  1314  <li><p><a href="#concept-event-dispatch" title="concept-event-dispatch">Dispatch</a> the
  1315  <var title="">event</var> and return the value that returns.
  1316 </ol>
  1317 
  1318 
  1319 <h3 id="dispatching-events"><span class="secno">4.6 </span>Dispatching events</h3>
  1320 
  1321 <p>To <dfn id="concept-event-dispatch" title="concept-event-dispatch">dispatch</dfn> an
  1322 <a href="#concept-event" title="concept-event">event</a> to a given object run these steps:
  1323 <!-- other specifications turn this into a requirement  -->
  1324 
  1325 <ol>
  1326  <li><p>Let <var title="">event</var> be the
  1327  <a href="#concept-event" title="concept-event">event</a> that is dispatched.
  1328 
  1329  <li><p>Set <var title="">event</var>'s <a href="#dispatch-flag">dispatch flag</a>.
  1330 
  1331  <li><p>Initialize <var title="">event</var>'s
  1332  <code title="dom-Event-target"><a href="#dom-event-target">target</a></code> attribute to the object to which
  1333  <var title="">event</var> is dispatched.
  1334 
  1335  <li><p>If <var title="">event</var>'s
  1336  <code title="dom-Event-target"><a href="#dom-event-target">target</a></code> attribute value is
  1337  <a href="#concept-tree-participate" title="concept-tree-participate">participating</a> in a
  1338  <a href="#concept-tree" title="concept-tree">tree</a>, let <var title="">event path</var> be a
  1339  static ordered list of all its
  1340  <a href="#concept-tree-ancestor" title="concept-tree-ancestor">ancestors</a> in
  1341  <a href="#concept-tree-order" title="concept-tree-order">tree order</a>, or let
  1342  <var title="">event path</var> be the empty list otherwise.
  1343 
  1344  <li><p>Initialize <var title="">event</var>'s
  1345  <code title="dom-Event-eventPhase"><a href="#dom-event-eventphase">eventPhase</a></code> attribute to
  1346  <code title="dom-Event-CAPTURING_PHASE"><a href="#dom-event-capturing_phase">CAPTURING_PHASE</a></code>.
  1347 
  1348  <li><p>For each object in the <var title="">event path</var>
  1349  <a href="#concept-event-listener-invoke" title="concept-event-listener-invoke">invoke</a> its
  1350  <a href="#concept-event-listener" title="concept-event-listener">event listeners</a> with event
  1351  <var title="">event</var>, as long as <var title="">event</var>'s
  1352  <a href="#stop-propagation-flag">stop propagation flag</a> is unset.
  1353 
  1354  <li><p>Initialize <var title="">event</var>'s
  1355  <code title="dom-Event-eventPhase"><a href="#dom-event-eventphase">eventPhase</a></code> attribute to
  1356  <code title="dom-Event-AT_TARGET"><a href="#dom-event-at_target">AT_TARGET</a></code>.
  1357 
  1358  <li><p><a href="#concept-event-listener-invoke" title="concept-event-listener-invoke">Invoke</a> the
  1359  <a href="#concept-event-listener" title="concept-event-listener">event listeners</a> of
  1360  <var title="">event</var>'s <code title="dom-Event-target"><a href="#dom-event-target">target</a></code>
  1361  attribute value with <var title="">event</var>, if <var title="">event</var>'s
  1362  <a href="#stop-propagation-flag">stop propagation flag</a> is unset.
  1363 
  1364  <li>
  1365   <p>If <var title="">event</var>'s
  1366   <code title="dom-Event-bubbles"><a href="#dom-event-bubbles">bubbles</a></code> attribute value is true, run
  1367   these substeps:
  1368 
  1369   <ol>
  1370    <li><p>Reverse the order of <var title="">event path</var>.
  1371 
  1372    <li><p>Initialize <var title="">event</var>'s
  1373    <code title="dom-Event-eventPhase"><a href="#dom-event-eventphase">eventPhase</a></code> attribute to
  1374    <code title="dom-Event-BUBBLING_PHASE"><a href="#dom-event-bubbling_phase">BUBBLING_PHASE</a></code>.
  1375 
  1376    <li><p>For each object in the <var title="">event path</var>
  1377    <a href="#concept-event-listener-invoke" title="concept-event-listener-invoke">invoke</a> its
  1378    <a href="#concept-event-listener" title="concept-event-listener">event listeners</a>, with event
  1379    <var title="">event</var> as long as <var title="">event</var>'s
  1380    <a href="#stop-propagation-flag">stop propagation flag</a> is unset.
  1381   </ol>
  1382 
  1383  <li><p>Unset <var title="">event</var>'s <a href="#dispatch-flag">dispatch flag</a>.
  1384 
  1385  <li><p>Initialize <var title="">event</var>'s
  1386  <code title="dom-Event-eventPhase"><a href="#dom-event-eventphase">eventPhase</a></code> attribute to
  1387  <code title="dom-Event-NONE"><a href="#dom-event-none">NONE</a></code>.
  1388 
  1389  <li><p>Initialize <var title="">event</var>'s
  1390  <code title="dom-Event-currentTarget"><a href="#dom-event-currenttarget">currentTarget</a></code> attribute to null.
  1391 
  1392  <li><p>Return false if <var title="">event</var>'s <a href="#canceled-flag">canceled flag</a>
  1393  is set, or true otherwise.
  1394 </ol>
  1395 
  1396 
  1397 <p>To <dfn id="concept-event-listener-invoke" title="concept-event-listener-invoke">invoke</dfn> the
  1398 <a href="#concept-event-listener" title="concept-event-listener">event listeners</a> for an object with an
  1399 event run these steps:</p>
  1400 <ol>
  1401  <li><p>Let <var title="">event</var> be the
  1402  <a href="#concept-event" title="concept-event">event</a> for which the
  1403  <a href="#concept-event-listener" title="concept-event-listener">event listeners</a> are invoked.
  1404  <li><p>Let <var title="">listeners</var> be a static list of the
  1405  <a href="#concept-event-listener" title="concept-event-listener">event listeners</a> associated with
  1406  the object for which these steps are run.
  1407  <li><p>Initialize <var title="">event</var>'s
  1408  <code title="dom-Event-currentTarget"><a href="#dom-event-currenttarget">currentTarget</a></code> attribute to the
  1409  object for which these steps are run.
  1410  <li>
  1411   <p>Then run these substeps for each
  1412   <a href="#concept-event-listener" title="concept-event-listener">event listener</a> in
  1413   <var title="">listeners</var>:</p>
  1414   <ol>
  1415    <li><p>If <var title="">event</var>'s
  1416    <a href="#stop-immediate-propagation-flag">stop immediate propagation flag</a> is set, terminate the
  1417    <a href="#concept-event-listener-invoke" title="concept-event-listener-invoke">invoke</a> algorithm.
  1418    <li><p>Let <var title="">listener</var> be the
  1419    <a href="#concept-event-listener" title="concept-event-listener">event listener</a>.
  1420    <li><p>If <var title="">event</var>'s <code title="dom-Event-type"><a href="#dom-event-type">type</a></code>
  1421    attribute value is not <var title="">listener</var>'s <b>type</b>, terminate
  1422    these substeps (and run them for the next
  1423    <a href="#concept-event-listener" title="concept-event-listener">event listener</a>).
  1424    <li><p>If <var title="">event</var>'s
  1425    <code title="dom-Event-eventPhase"><a href="#dom-event-eventphase">eventPhase</a></code> attribute value is
  1426    <code title="dom-Event-CAPTURING_PHASE"><a href="#dom-event-capturing_phase">CAPTURING_PHASE</a></code> and
  1427    <var title="">listener</var>'s <b>capture</b> is false, terminate these
  1428    substeps (and run them for the next
  1429    <a href="#concept-event-listener" title="concept-event-listener">event listener</a>).
  1430    <li><p>If <var title="">event</var>'s
  1431    <code title="dom-Event-eventPhase"><a href="#dom-event-eventphase">eventPhase</a></code> attribute value is
  1432    <code title="dom-Event-BUBBLING_PHASE"><a href="#dom-event-bubbling_phase">BUBBLING_PHASE</a></code> and
  1433    <var title="">listener</var>'s <b>capture</b> is true, terminate these
  1434    substeps (and run them for the next
  1435    <a href="#concept-event-listener" title="concept-event-listener">event listener</a>).
  1436    <li><p>If <var title="">listener</var>'s <b>callback</b> is a
  1437    Function<!-- WebIDL uses <span class=estype> --> object, its
  1438    <a class="external" data-anolis-spec="webidl" href="http://dev.w3.org/2006/webapi/WebIDL/#dfn-callback-this-value">callback this value</a> is the
  1439    <var title="">event</var>'s
  1440    <code title="dom-Event-currentTarget"><a href="#dom-event-currenttarget">currentTarget</a></code> attribute value.
  1441    <li><p>Call <var title="">listener</var>'s <b>callback</b>, with the event
  1442    passed to this algorithm as the first argument.
  1443   </ol>
  1444  </li>
  1445 </ol>
  1446 
  1447 
  1448 <h3 id="firing-events"><span class="secno">4.7 </span>Firing events</h3>
  1449 
  1450 <p>To
  1451 <dfn id="concept-event-fire" title="concept-event-fire">fire an event named <var title="">e</var></dfn>
  1452 means that an <a href="#concept-event" title="concept-event">event</a> using the
  1453 <code><a href="#event">Event</a></code> interface, with its
  1454 <code title="dom-Event-type"><a href="#dom-event-type">type</a></code> attribute initialized to
  1455 <var title="">e</var>, and its <code title="dom-Event-isTrusted"><a href="#dom-event-istrusted">isTrusted</a></code>
  1456 attribute initialized to true, is to be
  1457 <a href="#concept-event-dispatch" title="concept-event-dispatch">dispatched</a> to the given object.
  1458 
  1459 <p class="note">Fire is short for initializing and
  1460 <a href="#concept-event-dispatch" title="concept-event-dispatch">dispatching</a> an
  1461 <a href="#concept-event" title="concept-event">event</a>.
  1462 
  1463 <p class="note"><a href="#concept-event-fire" title="concept-event-fire">Fire an event</a> is a
  1464 concept to make initializing and
  1465 <a href="#concept-event-dispatch" title="concept-event-dispatch">dispatching</a> an
  1466 <a href="#concept-event" title="concept-event">event</a> easier to write down. If the
  1467 <a href="#concept-event" title="concept-event">event</a> needs its <code>bubbles</code> or
  1468 <code>cancelable</code> attribute initialized, one could write
  1469 "<a href="#concept-event-fire" title="concept-event-fire">fire an event</a> named
  1470 <code title="">submit</code> with its <code>cancelable</code> attribute
  1471 initialized to true".
  1472 
  1473 
  1474 
  1475 <h2 id="nodes"><span class="secno">5 </span>Nodes</h2>
  1476 
  1477 <h3 id="introduction-to-the-dom"><span class="secno">5.1 </span>Introduction to "The DOM"</h3>
  1478 
  1479 <p>In its original sense, "The DOM" is an API for
  1480 accessing and manipulating documents (in particular, HTML and XML
  1481 documents). In this specification, the term "document" is used for any
  1482 markup-based resource, ranging from short static documents to long essays or
  1483 reports with rich multimedia, as well as to fully-fledged interactive
  1484 applications.
  1485 
  1486 <p>These documents are presented as a
  1487 <a href="#concept-tree" title="concept-tree">tree</a> of
  1488 <a href="#concept-node" title="concept-node">nodes</a> of various types. Some of those
  1489 <a href="#concept-node" title="concept-node">nodes</a> can have
  1490 <a href="#concept-tree-child" title="concept-tree-child">child</a>
  1491 <a href="#concept-node" title="concept-node">nodes</a>, while others are leaves. These
  1492 restrictions are explained in <a href="#node-tree">the <cite>Node tree</cite>
  1493 section</a>, and the descriptions of the distinct types of
  1494 <a href="#concept-node" title="concept-node">nodes</a> comprise the remaining sections in
  1495 this chapter.
  1496 
  1497 <p>To illustrate, consider this HTML document:
  1498 
  1499 <pre><code>&lt;!DOCTYPE html&gt;
  1500 &lt;html class=e&gt;
  1501  &lt;head&gt;&lt;title&gt;Aliens?&lt;/title&gt;&lt;/head&gt;
  1502  &lt;body&gt;Why yes.&lt;/body&gt;
  1503 &lt;/html&gt;</code></pre>
  1504 
  1505 <p>It is represented as follows:
  1506 
  1507 <ul class="domTree">
  1508  <li>
  1509   <a href="#concept-document" title="concept-document">Document</a>
  1510   <ul>
  1511    <li class="t10"><a href="#concept-doctype" title="concept-doctype">Doctype:</a> <code>html</code></li>
  1512    <li class="t1"><a href="#concept-element" title="concept-element">Element:</a> <code>html</code> <span class="t2"><code class="attribute name">class</code>="<code class="attribute value">e</code>"</span>
  1513     <ul>
  1514      <li class="t1">
  1515       <a href="#concept-element" title="concept-element">Element:</a> <code>head</code>
  1516       <ul>
  1517        <li class="t1">
  1518         <a href="#concept-element" title="concept-element">Element:</a> <code>title</code>
  1519         <ul>
  1520          <li class="t3"><code><a href="#text">Text</a></code>: <span>Aliens?</span></li>
  1521         </ul>
  1522        </li>
  1523       </ul>
  1524      </li>
  1525      <li class="t3"><code><a href="#text">Text</a></code>: <span>⏎␣</span></li>
  1526      <li class="t1">
  1527       <a href="#concept-element" title="concept-element">Element:</a> <code>body</code>
  1528       <ul>
  1529        <li class="t3"><code><a href="#text">Text</a></code>: <span>Why yes.⏎</span></li>
  1530       </ul>
  1531      </li>
  1532     </ul>
  1533    </li>
  1534   </ul>
  1535  </li>
  1536 </ul>
  1537 
  1538 <!--
  1539 http://software.hixie.ch/utilities/js/live-dom-viewer/?%3C!DOCTYPE%20html%3E%0D%0A%3Chtml%20class%3De%3E%0D%0A%20%3Chead%3E%3Ctitle%3EAliens%3F%3C%2Ftitle%3E%3C%2Fhead%3E%0D%0A%20%3Cbody%3EWhy%20yes.%3C%2Fbody%3E%0D%0A%3C%2Fhtml%3E
  1540 -->
  1541 
  1542 <p>Note that, due to the magic that is
  1543 <a class="external" data-anolis-spec="html" href="http://www.whatwg.org/specs/web-apps/current-work/multipage/parsing.html#html-parser" title="HTML parser">HTML parsing</a>, not all
  1544 <a href="#space-character" title="space character">space characters</a> were turned into
  1545 <code><a href="#text">Text</a></code> <a href="#concept-node" title="concept-node">nodes</a>, but the general
  1546 concept is clear. Markup goes in, a <a href="#concept-tree" title="concept-tree">tree</a> of
  1547 <a href="#concept-node" title="concept-node">nodes</a> comes out.
  1548 <!-- You /can/ explain that! harharhar -->
  1549 
  1550 <p class="note">The most excellent
  1551 <a href="http://software.hixie.ch/utilities/js/live-dom-viewer/">Live DOM Viewer</a>
  1552 can be used to explore this matter in more detail.
  1553 
  1554 <p class="XXX">How much should be explained here? Ideas?
  1555 
  1556 
  1557 <h3 id="node-tree"><span class="secno">5.2 </span>Node tree</h3>
  1558 
  1559 <p>Objects implementing the <code><a href="#document">Document</a></code>,
  1560 <code><a href="#documentfragment">DocumentFragment</a></code>, <code><a href="#documenttype">DocumentType</a></code>,
  1561 <code><a href="#element">Element</a></code>, <code><a href="#text">Text</a></code>, <code><a href="#processinginstruction">ProcessingInstruction</a></code>,
  1562 or <code><a href="#comment">Comment</a></code> interface (simply called
  1563 <dfn id="concept-node" title="concept-node">nodes</dfn>)
  1564 <a href="#concept-tree-participate" title="concept-tree-participate">participate</a> in a
  1565 <a href="#concept-tree" title="concept-tree">tree</a>.
  1566 
  1567 <p>A <a href="#concept-tree" title="concept-tree">tree</a> of
  1568 <a href="#concept-node" title="concept-node">nodes</a> is constrained as follows, expressed
  1569 as a relationship between the type of <a href="#concept-node" title="concept-node">node</a>
  1570 and its allowed <a href="#concept-tree-child" title="concept-tree-child">children</a>:
  1571 <dl>
  1572  <dt><code><a href="#document">Document</a></code>
  1573  <dd>
  1574   <p>In <a href="#concept-tree-order" title="concept-tree-order">tree order</a>:
  1575   <ol>
  1576    <li><p>Zero or more nodes each of which is either
  1577    <code><a href="#processinginstruction">ProcessingInstruction</a></code> or <code><a href="#comment">Comment</a></code>.
  1578    <li><p>Optionally one <code><a href="#documenttype">DocumentType</a></code> node.
  1579    <li><p>Zero or more nodes each of which is either
  1580    <code><a href="#processinginstruction">ProcessingInstruction</a></code> or <code><a href="#comment">Comment</a></code>.
  1581    <li><p>Optionally one <code><a href="#element">Element</a></code> node.
  1582    <li><p>Zero or more nodes each of which is either
  1583    <code><a href="#processinginstruction">ProcessingInstruction</a></code> or <code><a href="#comment">Comment</a></code>.
  1584   </ol>
  1585  <dt><code><a href="#documentfragment">DocumentFragment</a></code>
  1586  <dt><code><a href="#element">Element</a></code>
  1587  <dd><p>Zero or more nodes each of which is one of <code><a href="#element">Element</a></code>,
  1588  <code><a href="#processinginstruction">ProcessingInstruction</a></code>, <code><a href="#comment">Comment</a></code>, or
  1589  <code><a href="#text">Text</a></code>.
  1590  <dt><code><a href="#documenttype">DocumentType</a></code>
  1591  <dt><code><a href="#text">Text</a></code>
  1592  <dt><code><a href="#processinginstruction">ProcessingInstruction</a></code>
  1593  <dt><code><a href="#comment">Comment</a></code>
  1594  <dd><p>None.
  1595 </dl>
  1596 <!--AttrExodus -->
  1597 
  1598 <p>The <dfn id="concept-node-length" title="concept-node-length">length</dfn> of a
  1599 <a href="#concept-node" title="concept-node">node</a> <var title="">node</var> depends on
  1600 <var title="">node</var>:
  1601 <dl class="switch">
  1602  <dt><code><a href="#documenttype">DocumentType</a></code>
  1603  <dd><p>Zero.
  1604 
  1605  <dt><code><a href="#text">Text</a></code>
  1606  <dt><code><a href="#processinginstruction">ProcessingInstruction</a></code>
  1607  <dt><code><a href="#comment">Comment</a></code>
  1608  <dd><p>Its <code title="dom-CharacterData-length"><a href="#dom-characterdata-length">length</a></code> attribute
  1609  value.
  1610 
  1611  <dt>Any other node
  1612  <dd><p>Its number of <a href="#concept-tree-child" title="concept-tree-child">children</a>.
  1613 </dl>
  1614 
  1615 <p>A <a href="#concept-node" title="concept-node">node</a> is considered
  1616 <dfn id="concept-node-empty" title="concept-node-empty">empty</dfn> if its
  1617 <a href="#concept-node-length" title="concept-node-length">length</a> is zero.
  1618 
  1619 
  1620 <h4 id="mutation-algorithms"><span class="secno">5.2.1 </span>Mutation algorithms</h4>
  1621 
  1622 <p>At certain points in the algorithms below it is said that a
  1623 <dfn id="node-is-inserted">node is inserted</dfn> or a <dfn id="node-is-removed">node is removed</dfn>. These are
  1624 hooks for <a href="#other-applicable-specifications">other applicable specifications</a> to process the
  1625 <a href="#concept-node" title="concept-node">nodes</a> that have been inserted or removed
  1626 further and ensures that when multiple <a href="#concept-node" title="concept-node">nodes</a>
  1627 are inserted or removed this happens atomically.
  1628 
  1629 <p>To <dfn id="concept-node-pre-insert" title="concept-node-pre-insert">pre-insert</dfn> a
  1630 <var title="">node</var> into a <var title="">parent</var> before a
  1631 <var title="">child</var>, run these steps:
  1632 
  1633 <ol>
  1634  <li><p>If <var title="">parent</var> is not a <code><a href="#document">Document</a></code>,
  1635  <code><a href="#documentfragment">DocumentFragment</a></code>, or <code><a href="#element">Element</a></code>
  1636  <a href="#concept-node" title="concept-node">node</a>,
  1637  <a href="#concept-throw" title="concept-throw">throw</a> a
  1638  "<code><a href="#hierarchyrequesterror">HierarchyRequestError</a></code>" and terminate these steps.
  1639 
  1640  <li><p>If <var title="">node</var> is an
  1641  <a href="#concept-tree-inclusive-ancestor" title="concept-tree-inclusive-ancestor">inclusive ancestor</a> of
  1642  <var title="">parent</var>, <a href="#concept-throw" title="concept-throw">throw</a> a
  1643  "<code><a href="#hierarchyrequesterror">HierarchyRequestError</a></code>" and terminate these steps.
  1644 
  1645  <li><p>If <var title="">child</var> is not null and its
  1646  <a href="#concept-tree-parent" title="concept-tree-parent">parent</a> is not
  1647  <var title="">parent</var>, <a href="#concept-throw" title="concept-throw">throw</a> a
  1648  "<code><a href="#notfounderror">NotFoundError</a></code>" exception and terminate these steps.
  1649 
  1650  <li>
  1651   <p>If <var title="">parent</var> is a
  1652   <a href="#concept-document" title="concept-document">document</a>, run these substeps:
  1653 
  1654   <ol>
  1655    <li><p>If <var title="">node</var> is not a <code><a href="#documentfragment">DocumentFragment</a></code>,
  1656    <code><a href="#documenttype">DocumentType</a></code>, <code><a href="#element">Element</a></code>,
  1657    <code><a href="#processinginstruction">ProcessingInstruction</a></code>, or <code><a href="#comment">Comment</a></code>
  1658    <a href="#concept-node" title="concept-node">node</a>,
  1659    <a href="#concept-throw" title="concept-throw">throw</a> a
  1660    "<code><a href="#hierarchyrequesterror">HierarchyRequestError</a></code>" and terminate these steps.
  1661 
  1662    <li>
  1663     <p>If <var title="">node</var> is a <code><a href="#documentfragment">DocumentFragment</a></code>
  1664     <a href="#concept-node" title="concept-node">node</a>, run these inner substeps:
  1665 
  1666     <ol>
  1667      <li><p>If <var title="">node</var> has more than one
  1668      <a href="#concept-element" title="concept-element">element</a>
  1669      <a href="#concept-tree-child" title="concept-tree-child">child</a> or has a <code><a href="#text">Text</a></code>
  1670      <a href="#concept-node" title="concept-node">node</a>
  1671      <a href="#concept-tree-child" title="concept-tree-child">child</a>,
  1672      <a href="#concept-throw" title="concept-throw">throw</a> a
  1673      "<code><a href="#hierarchyrequesterror">HierarchyRequestError</a></code>" and terminate these steps.
  1674 
  1675      <li><p>If <var title="">node</var> has one
  1676      <a href="#concept-element" title="concept-element">element</a>
  1677      <a href="#concept-tree-child" title="concept-tree-child">child</a>, and
  1678      <var title="">parent</var> has an
  1679      <a href="#concept-element" title="concept-element">element</a>
  1680      <a href="#concept-tree-child" title="concept-tree-child">child</a>,
  1681      <var title="">child</var> is a <a href="#concept-doctype" title="concept-doctype">doctype</a>,
  1682      or <var title="">child</var> is not null and a
  1683      <a href="#concept-doctype" title="concept-doctype">doctype</a> is
  1684      <a href="#concept-tree-following" title="concept-tree-following">following</a>
  1685      <var title="">child</var>, <a href="#concept-throw" title="concept-throw">throw</a> a
  1686      "<code><a href="#hierarchyrequesterror">HierarchyRequestError</a></code>" and terminate these steps.
  1687      <!--"inclusively following"-->
  1688     </ol>
  1689 
  1690    <li><p>If <var title="">node</var> is an
  1691    <a href="#concept-element" title="concept-element">element</a>, and
  1692    <var title="">parent</var> has an <a href="#concept-element" title="concept-element">element</a>
  1693    <a href="#concept-tree-child" title="concept-tree-child">child</a>,
  1694    <var title="">child</var> is a <a href="#concept-doctype" title="concept-doctype">doctype</a>,
  1695    or <var title="">child</var> is not null and a
  1696    <a href="#concept-doctype" title="concept-doctype">doctype</a> is
  1697    <a href="#concept-tree-following" title="concept-tree-following">following</a>
  1698    <var title="">child</var>, <a href="#concept-throw" title="concept-throw">throw</a> a
  1699    "<code><a href="#hierarchyrequesterror">HierarchyRequestError</a></code>" and terminate these steps.
  1700    <!--"inclusively following"-->
  1701 
  1702    <li><p>If <var title="">node</var> is a
  1703    <a href="#concept-doctype" title="concept-doctype">doctype</a> and either
  1704    <var title="">parent</var> has a <a href="#concept-doctype" title="concept-doctype">doctype</a>
  1705    <a href="#concept-tree-child" title="concept-tree-child">child</a>, an
  1706    <a href="#concept-element" title="concept-element">element</a> is
  1707    <a href="#concept-tree-preceding" title="concept-tree-preceding">preceding</a>
  1708    <var title="">child</var>, or <var title="">child</var> is null and
  1709    <var title="">parent</var> has an <a href="#concept-element" title="concept-element">element</a>
  1710    <a href="#concept-tree-child" title="concept-tree-child">child</a>,
  1711    <a href="#concept-throw" title="concept-throw">throw</a> a
  1712    "<code><a href="#hierarchyrequesterror">HierarchyRequestError</a></code>" and terminate these steps.
  1713   </ol>
  1714 
  1715  <li><p>Otherwise, <var title="">parent</var> is a
  1716  <code><a href="#documentfragment">DocumentFragment</a></code> or <code><a href="#element">Element</a></code>
  1717  <a href="#concept-node" title="concept-node">node</a>. If <var title="">node</var> is not a
  1718  <code><a href="#documentfragment">DocumentFragment</a></code>, <code><a href="#element">Element</a></code>, <code><a href="#text">Text</a></code>,
  1719  <code><a href="#processinginstruction">ProcessingInstruction</a></code>, or <code><a href="#comment">Comment</a></code>
  1720  <a href="#concept-node" title="concept-node">node</a>,
  1721  <a href="#concept-throw" title="concept-throw">throw</a> a
  1722  "<code><a href="#hierarchyrequesterror">HierarchyRequestError</a></code>" and terminate these steps.
  1723 
  1724  <li><p>Let <var title="">reference child</var> be <var title="">child</var>.
  1725 
  1726  <li><p>If <var title="">reference child</var> is <var title="">node</var>, set it
  1727  to <var title="">node</var>'s
  1728  <a href="#concept-tree-next-sibling" title="concept-tree-next-sibling">next sibling</a>.
  1729 
  1730  <li><p><a href="#concept-node-adopt" title="concept-node-adopt">Adopt</a>
  1731  <var title="">node</var> with <var title="">parent</var>'s
  1732  <a href="#concept-node-document" title="concept-node-document">node document</a>.
  1733 
  1734  <li><p><a href="#concept-node-insert" title="concept-node-insert">Insert</a> <var title="">node</var>
  1735  into <var title="">parent</var> before <var title="">reference child</var>.
  1736 
  1737  <li><p>Return <var title="">node</var>.
  1738  <!-- technically this is post-insert -->
  1739 </ol>
  1740 
  1741 
  1742 <p>To <dfn id="concept-node-insert" title="concept-node-insert">insert</dfn> a <var title="">node</var>
  1743 into a <var title="">parent</var> before a <var title="">child</var>, optionally
  1744 with a <i title="">suppress observers flag</i>, run these steps:
  1745 
  1746 <ol>
  1747  <li><p>Let <var title="">count</var> be the number of
  1748  <a href="#concept-tree-child" title="concept-tree-child">children</a> of <var title="">node</var> if
  1749  it is a <code><a href="#documentfragment">DocumentFragment</a></code> <a href="#concept-node" title="concept-node">node</a>,
  1750  or one otherwise.
  1751 
  1752  <li><p>For each <a href="#concept-range" title="concept-range">range</a> whose
  1753  <a href="#concept-range-start-node" title="concept-range-start-node">start node</a> is
  1754  <var title="">parent</var> and
  1755  <a href="#concept-range-start-offset" title="concept-range-start-offset">start offset</a> is greater than
  1756  <var title="">child</var>'s <a href="#concept-tree-index" title="concept-tree-index">index</a>,
  1757  increase its <a href="#concept-range-start-offset" title="concept-range-start-offset">start offset</a> by
  1758  <var title="">count</var>.
  1759 
  1760  <li><p>For each <a href="#concept-range" title="concept-range">range</a> whose
  1761  <a href="#concept-range-end-node" title="concept-range-end-node">end node</a> is
  1762  <var title="">parent</var> and
  1763  <a href="#concept-range-end-offset" title="concept-range-end-offset">end offset</a> is greater than
  1764  <var title="">child</var>'s <a href="#concept-tree-index" title="concept-tree-index">index</a>,
  1765  increase its <a href="#concept-range-end-offset" title="concept-range-end-offset">end offset</a> by
  1766  <var title="">count</var>.
  1767 
  1768  <li><p>Let <var title="">nodes</var> be <var title="">node</var>'s
  1769  <a href="#concept-tree-child" title="concept-tree-child">children</a> if <var title="">node</var> is
  1770  a <code><a href="#documentfragment">DocumentFragment</a></code> <a href="#concept-node" title="concept-node">node</a>, or a
  1771  list containing solely <var title="">node</var> otherwise.
  1772 
  1773  <li>
  1774   <p>If <var title="">node</var> is a <code><a href="#documentfragment">DocumentFragment</a></code>
  1775   <a href="#concept-node" title="concept-node">node</a>, <a href="#queue-a-mutation-record">queue a mutation record</a>
  1776   of "<code>childList</code>" for <var title="">node</var> with removedNodes
  1777   <var title="">nodes</var>.
  1778 
  1779   <p class="note">This step does intentionally not pay attention to the
  1780   <i title="">suppress observers flag</i>.
  1781 
  1782  <li><p>If <var title="">node</var> is a <code><a href="#documentfragment">DocumentFragment</a></code>
  1783  <a href="#concept-node" title="concept-node">node</a>,
  1784  <a href="#concept-node-remove" title="concept-node-remove">remove</a> its
  1785  <a href="#concept-tree-child" title="concept-tree-child">children</a> with the
  1786  <i title="">suppress observers flag</i> set.
  1787 
  1788  <li><p>If <i title="">suppress observers flag</i> is unset,
  1789  <a href="#queue-a-mutation-record">queue a mutation record</a> of "<code>childList</code>" for
  1790  <var title="">parent</var> with addedNodes <var title="">nodes</var>,
  1791  nextSibling <var title="">child</var>, and previousSibling
  1792  <var title="">child</var>'s
  1793  <a href="#concept-tree-previous-sibling" title="concept-tree-previous-sibling">previous sibling</a>
  1794  or <var title="">parent</var>'s
  1795  <a href="#concept-tree-last-child" title="concept-tree-last-child">last child</a> if
  1796  <var title="">child</var> is null.
  1797 
  1798  <li><p>Insert all <a href="#concept-node" title="concept-node">nodes</a> in
  1799  <var title="">nodes</var> before <var title="">child</var> or at the end of
  1800  <var title="">parent</var> if <var title="">child</var> is null.
  1801 
  1802  <li><p>If <i title="">suppress observers flag</i> is unset, for each
  1803  <a href="#concept-node" title="concept-node">node</a> in <var title="">nodes</var>, in
  1804  <a href="#concept-tree-order" title="concept-tree-order">tree order</a> run
  1805  <a href="#node-is-inserted">node is inserted</a>.
  1806 </ol>
  1807 
  1808 
  1809 <p>To <dfn id="concept-node-append" title="concept-node-append">append</dfn> a <var title="">node</var>
  1810 to a <var title="">parent</var>,
  1811 <a href="#concept-node-pre-insert" title="concept-node-pre-insert">pre-insert</a> <var title="">node</var>
  1812 into <var title="">parent</var> before null.
  1813 
  1814 
  1815 <p>To <dfn id="concept-node-replace" title="concept-node-replace">replace</dfn> a <var title="">child</var>
  1816 with <var title="">node</var> within a <var title="">parent</var>, run these
  1817 steps:
  1818 
  1819 <ol>
  1820  <li>
  1821   <p>If <var title="">child</var>'s
  1822   <a href="#concept-tree-parent" title="concept-tree-parent">parent</a> is not
  1823   <var title="">parent</var>, <a href="#concept-throw" title="concept-throw">throw</a> a
  1824   "<code><a href="#notfounderror">NotFoundError</a></code>" exception and terminate these steps.
  1825 
  1826   <p class="note">This implies <var title="">parent</var> is a
  1827   <code><a href="#document">Document</a></code>, <code><a href="#documentfragment">DocumentFragment</a></code>, or
  1828   <code><a href="#element">Element</a></code> <a href="#concept-node" title="concept-node">node</a>.
  1829 
  1830  <li><p>If <var title="">node</var> is an
  1831  <a href="#concept-tree-inclusive-ancestor" title="concept-tree-inclusive-ancestor">inclusive ancestor</a> of
  1832  <var title="">parent</var>, <a href="#concept-throw" title="concept-throw">throw</a> a
  1833  "<code><a href="#hierarchyrequesterror">HierarchyRequestError</a></code>" and terminate these steps.
  1834 
  1835  <li>
  1836   <p>If <var title="">parent</var> is a
  1837   <a href="#concept-document" title="concept-document">document</a>, run these substeps:
  1838 
  1839   <ol>
  1840    <li><p>If <var title="">node</var> is not a <code><a href="#documentfragment">DocumentFragment</a></code>,
  1841    <code><a href="#documenttype">DocumentType</a></code>, <code><a href="#element">Element</a></code>,
  1842    <code><a href="#processinginstruction">ProcessingInstruction</a></code>, or <code><a href="#comment">Comment</a></code>
  1843    <a href="#concept-node" title="concept-node">node</a>,
  1844    <a href="#concept-throw" title="concept-throw">throw</a> a
  1845    "<code><a href="#hierarchyrequesterror">HierarchyRequestError</a></code>" and terminate these steps.
  1846 
  1847    <li>
  1848     <p>If <var title="">node</var> is a <code><a href="#documentfragment">DocumentFragment</a></code>
  1849     <a href="#concept-node" title="concept-node">node</a>, run these inner substeps:
  1850 
  1851     <ol>
  1852      <li><p>If <var title="">node</var> has more than one
  1853      <a href="#concept-element" title="concept-element">element</a>
  1854      <a href="#concept-tree-child" title="concept-tree-child">child</a> or has a <code><a href="#text">Text</a></code>
  1855      <a href="#concept-node" title="concept-node">node</a>
  1856      <a href="#concept-tree-child" title="concept-tree-child">child</a>,
  1857      <a href="#concept-throw" title="concept-throw">throw</a> a
  1858      "<code><a href="#hierarchyrequesterror">HierarchyRequestError</a></code>" and terminate these steps.
  1859 
  1860      <li><p>If <var title="">node</var> has one
  1861      <a href="#concept-element" title="concept-element">element</a>
  1862      <a href="#concept-tree-child" title="concept-tree-child">child</a> and either
  1863      <var title="">parent</var> has an
  1864      <a href="#concept-element" title="concept-element">element</a>
  1865      <a href="#concept-tree-child" title="concept-tree-child">child</a> that is not
  1866      <var title="">child</var> or a <a href="#concept-doctype" title="concept-doctype">doctype</a>
  1867      is <a href="#concept-tree-following" title="concept-tree-following">following</a>
  1868      <var title="">child</var>, <a href="#concept-throw" title="concept-throw">throw</a> a
  1869      "<code><a href="#hierarchyrequesterror">HierarchyRequestError</a></code>" and terminate these steps.
  1870     </ol>
  1871 
  1872    <li><p>If <var title="">node</var> is an
  1873    <a href="#concept-element" title="concept-element">element</a> and either
  1874    <var title="">parent</var> has an <a href="#concept-element" title="concept-element">element</a>
  1875    <a href="#concept-tree-child" title="concept-tree-child">child</a> that is not
  1876    <var title="">child</var> or a <a href="#concept-doctype" title="concept-doctype">doctype</a> is
  1877    <a href="#concept-tree-following" title="concept-tree-following">following</a>
  1878    <var title="">child</var>, <a href="#concept-throw" title="concept-throw">throw</a> a
  1879    "<code><a href="#hierarchyrequesterror">HierarchyRequestError</a></code>" and terminate these steps.
  1880 
  1881    <li><p>If <var title="">node</var> is a
  1882    <a href="#concept-doctype" title="concept-doctype">doctype</a> and either
  1883    <var title="">parent</var> has a <a href="#concept-doctype" title="concept-doctype">doctype</a>
  1884    <a href="#concept-tree-child" title="concept-tree-child">child</a> that is not
  1885    <var title="">child</var>, or an <a href="#concept-element" title="concept-element">element</a>
  1886    is <a href="#concept-tree-preceding" title="concept-tree-preceding">preceding</a>
  1887    <var title="">child</var>, <a href="#concept-throw" title="concept-throw">throw</a> a
  1888    "<code><a href="#hierarchyrequesterror">HierarchyRequestError</a></code>" and terminate these steps.
  1889   </ol>
  1890 
  1891  <li><p>Otherwise if <var title="">parent</var> is a
  1892  <code><a href="#documentfragment">DocumentFragment</a></code> or <code><a href="#element">Element</a></code>
  1893  <a href="#concept-node" title="concept-node">node</a> and <var title="">node</var> is not a
  1894  <code><a href="#documentfragment">DocumentFragment</a></code>, <code><a href="#element">Element</a></code>, <code><a href="#text">Text</a></code>,
  1895  <code><a href="#processinginstruction">ProcessingInstruction</a></code>, or <code><a href="#comment">Comment</a></code>
  1896  <a href="#concept-node" title="concept-node">node</a>,
  1897  <a href="#concept-throw" title="concept-throw">throw</a> a
  1898  "<code><a href="#hierarchyrequesterror">HierarchyRequestError</a></code>" and terminate these steps.
  1899 
  1900  <li><p>Let <var title="">reference child</var> be <var title="">child</var>'s
  1901  <a href="#concept-tree-next-sibling" title="concept-tree-next-sibling">next sibling</a>.
  1902 
  1903  <li><p>If <var title="">reference child</var> is <var title="">node</var>, set it
  1904  to <var title="">node</var>'s
  1905  <a href="#concept-tree-next-sibling" title="concept-tree-next-sibling">next sibling</a>.
  1906 
  1907  <li><p><a href="#concept-node-adopt" title="concept-node-adopt">Adopt</a>
  1908  <var title="">node</var> with <var title="">parent</var>'s
  1909  <a href="#concept-node-document" title="concept-node-document">node document</a>.
  1910 
  1911  <li><p><a href="#concept-node-remove" title="concept-node-remove">Remove</a> <var title="">child</var>
  1912  from its <var title="">parent</var> with the
  1913  <i title="">suppress observers flag</i> set.
  1914 
  1915  <li><p><a href="#concept-node-insert" title="concept-node-insert">Insert</a> <var title="">node</var>
  1916  into <var title="">parent</var> before <var title="">reference child</var> with
  1917  the <i title="">suppress observers flag</i> set.
  1918 
  1919  <li><p>Let <var title="">nodes</var> be <var title="">node</var>'s
  1920  <a href="#concept-tree-child" title="concept-tree-child">children</a> if <var title="">node</var> is
  1921  a <code><a href="#documentfragment">DocumentFragment</a></code> <a href="#concept-node" title="concept-node">node</a>, or a
  1922  list containing solely <var title="">node</var> otherwise.
  1923 
  1924  <li><p><a href="#queue-a-mutation-record">queue a mutation record</a> of "<code>childList</code>" for
  1925  target <var title="">parent</var> with addedNodes
  1926  <var title="">nodes</var>, removedNodes a list solely containing
  1927  <var title="">child</var>, nextSibling <var title="">reference child</var>, and
  1928  previousSibling <var title="">child</var>'s
  1929  <a href="#concept-tree-previous-sibling" title="concept-tree-previous-sibling">previous sibling</a>.
  1930 
  1931  <li><p>Run <a href="#node-is-removed">node is removed</a> for <var title="">child</var>, and
  1932  then for each <a href="#concept-node" title="concept-node">node</a> in
  1933  <var title="">nodes</var>, in
  1934  <a href="#concept-tree-order" title="concept-tree-order">tree order</a>, run
  1935  <a href="#node-is-inserted">node is inserted</a>.
  1936 
  1937  <li><p>Return <var title="">child</var>.
  1938 </ol>
  1939 
  1940 
  1941 <p>To <dfn id="concept-node-replace-all" title="concept-node-replace-all">replace all</dfn> with a
  1942 <var title="">node</var> within a <var title="">parent</var>, run these steps:
  1943 
  1944 <ol>
  1945  <li><p><a href="#concept-node-adopt" title="concept-node-adopt">Adopt</a>
  1946  <var title="">node</var> with <var title="">parent</var>'s
  1947  <a href="#concept-node-document" title="concept-node-document">node document</a>.
  1948 
  1949  <li><p><a href="#concept-node-remove" title="concept-node-remove">Remove</a> all
  1950  <var title="">parent</var>'s <a href="#concept-tree-child" title="concept-tree-child">children</a>,
  1951  with the <i title="">suppress observers flag</i> set.
  1952 
  1953  <li><p>If <var title="">node</var> is not null,
  1954  <a href="#concept-node-insert" title="concept-node-insert">insert</a> <var title="">node</var> into
  1955  <var title="">parent</var> before null with the
  1956  <i title="">suppress observers flag</i> set.
  1957 
  1958  <li><p>Let <var title="">nodes</var> be null if <var title="">node</var> is null,
  1959  <var title="">node</var>'s <a href="#concept-tree-child" title="concept-tree-child">children</a> if
  1960  <var title="">node</var> is a <code><a href="#documentfragment">DocumentFragment</a></code>
  1961  <a href="#concept-node" title="concept-node">node</a>, or a list containing
  1962  <var title="">node</var> otherwise.
  1963 
  1964  <li><p><a href="#queue-a-mutation-record">queue a mutation record</a> of "<code>childList</code>" for
  1965  <var title="">parent</var> with addedNodes <var title="">nodes</var> and
  1966  removedNodes <var title="">parent</var>'s
  1967  <a href="#concept-tree-child" title="concept-tree-child">children</a>.
  1968 
  1969  <li><p>Run <a href="#node-is-removed">node is removed</a> for each
  1970  <a href="#concept-tree-child" title="concept-tree-child">child</a> of <var title="">parent</var>, in
  1971  <a href="#concept-tree-order" title="concept-tree-order">tree order</a>, and then
  1972  for each <a href="#concept-node" title="concept-node">node</a> in <var title="">nodes</var>, in
  1973  <a href="#concept-tree-order" title="concept-tree-order">tree order</a>, run
  1974  <a href="#node-is-inserted">node is inserted</a>.
  1975 </ol>
  1976 
  1977 <p class="note">This algorithm does not make any checks with regards to the
  1978 <a href="#node-tree">node tree</a>. Use it wisely.
  1979 
  1980 
  1981 <p>To <dfn id="concept-node-pre-remove" title="concept-node-pre-remove">pre-remove</dfn> a
  1982 <var title="">child</var> from a <var title="">parent</var>, run these steps:</p>
  1983 
  1984 <ol>
  1985  <li><p>If <var title="">child</var>'s
  1986  <a href="#concept-tree-parent" title="concept-tree-parent">parent</a> is not
  1987  <var title="">parent</var>, <a href="#concept-throw" title="concept-throw">throw</a> a
  1988  "<code><a href="#notfounderror">NotFoundError</a></code>" exception and terminate these steps.
  1989 
  1990  <li><p><a href="#concept-node-remove" title="concept-node-remove">Remove</a> <var title="">child</var>
  1991  from <var title="">parent</var>.
  1992 
  1993  <li><p>Return <var title="">child</var>.
  1994  <!-- technically this is post-remove -->
  1995 </ol>
  1996 
  1997 
  1998 <p>To <dfn id="concept-node-remove" title="concept-node-remove">remove</dfn> a <var title="">node</var>
  1999 from a <var title="">parent</var>, optionally with
  2000 <i title="">suppress observers flag</i> set, run these steps:
  2001 
  2002 <ol>
  2003  <li><p>Let <var title="">index</var> be <var title="">node</var>'s
  2004  <a href="#concept-tree-index" title="concept-tree-index">index</a>.
  2005 
  2006  <li><p>For each <a href="#concept-range" title="concept-range">range</a> whose
  2007  <a href="#concept-range-start-node" title="concept-range-start-node">start node</a> is a
  2008  <a href="#concept-tree-descendant" title="concept-tree-descendant">descendant</a> of
  2009  <var title="">node</var>, set its
  2010  <a href="#concept-range-start" title="concept-range-start">start</a> to
  2011  (<var title="">parent</var>, <var title="">index</var>).
  2012 
  2013  <li><p>For each <a href="#concept-range" title="concept-range">range</a> whose
  2014  <a href="#concept-range-end-node" title="concept-range-end-node">end node</a> is a
  2015  <a href="#concept-tree-descendant" title="concept-tree-descendant">descendant</a> of
  2016  <var title="">node</var>, set its
  2017  <a href="#concept-range-end" title="concept-range-end">end</a> to
  2018  (<var title="">parent</var>, <var title="">index</var>).
  2019 
  2020  <li><p>For each <a href="#concept-range" title="concept-range">range</a> whose
  2021  <a href="#concept-range-start-node" title="concept-range-start-node">start node</a> is
  2022  <var title="">parent</var> and
  2023  <a href="#concept-range-start-offset" title="concept-range-start-offset">start offset</a> is greater than
  2024  <var title="">index</var>, decrease its
  2025  <a href="#concept-range-start-offset" title="concept-range-start-offset">start offset</a> by one.
  2026 
  2027  <li><p>For each <a href="#concept-range" title="concept-range">range</a> whose
  2028  <a href="#concept-range-end-node" title="concept-range-end-node">end node</a> is
  2029  <var title="">parent</var> and
  2030  <a href="#concept-range-end-offset" title="concept-range-end-offset">end offset</a> is greater than
  2031  <var title="">index</var>, decrease its
  2032  <a href="#concept-range-end-offset" title="concept-range-end-offset">end offset</a> by one.
  2033 
  2034  <li><p>If <i title="">suppress observers flag</i> is unset,
  2035  <a href="#queue-a-mutation-record">queue a mutation record</a> of "<code>childList</code>" for
  2036  <var title="">parent</var> with removedNodes a list solely containing
  2037  <var title="">node</var>, nextSibling <var title="">node</var>'s
  2038  <a href="#concept-tree-next-sibling" title="concept-tree-next-sibling">next sibling</a>,
  2039  and previousSibling <var title="">node</var>'s
  2040  <a href="#concept-tree-previous-sibling" title="concept-tree-previous-sibling">previous sibling</a>.
  2041 
  2042  <li><p>For each <a href="#concept-tree-ancestor" title="concept-tree-ancestor">ancestor</a>
  2043  <var title="">ancestor</var> of <var title="">node</var>, if
  2044  <var title="">ancestor</var> has any
  2045  <a href="#registered-observer" title="registered observer">registered observers</a> whose
  2046  <b>options</b>'s
  2047  <code title="dom-MutationObserverInit-subtree">subtree</code> is true, then
  2048  for each such <a href="#registered-observer">registered observer</a>, append a
  2049  <a href="#transient-registered-observer">transient registered observer</a> whose <b>observer</b> and
  2050  <b>options</b> are identical to the <a href="#registered-observer">registered observer</a> to
  2051  <var title="">node</var>'s list of
  2052  <a href="#registered-observer" title="registered observer">registered observers</a>.
  2053 
  2054  <li><p>Remove <var title="">node</var> from its <var title="">parent</var>.
  2055 
  2056  <li><p>If <i title="">suppress observers flag</i> is unset, run
  2057  <a href="#node-is-removed">node is removed</a> for <var title="">node</var>.
  2058 </ol>
  2059 
  2060 
  2061 <h4 id="mutation-methods"><span class="secno">5.2.2 </span>Mutation methods</h4>
  2062 
  2063 <p>The <dfn id="mutation-method-macro">mutation method macro</dfn>:
  2064 
  2065 <ol>
  2066  <li><p>Let <var title="">node</var> be null.
  2067 
  2068  <li><p>Replace each string in <var title="">nodes</var> with a
  2069  <code><a href="#text">Text</a></code> <a href="#concept-node" title="concept-node">node</a> whose
  2070  <a href="#concept-cd-data" title="concept-CD-data">data</a> is the string value.
  2071 
  2072  <li>
  2073   <p>If <var title="">nodes</var> contains more than one
  2074   <a href="#concept-node" title="concept-node">node</a>, set <var title="">node</var> to a new
  2075   <code><a href="#documentfragment">DocumentFragment</a></code> and
  2076   <a href="#concept-node-append" title="concept-node-append">append</a> each
  2077   <a href="#concept-node" title="concept-node">node</a> in <var title="">nodes</var> to it. If
  2078   this throws an exception, re-throw the exception and terminate these
  2079   steps.
  2080 
  2081   <p>Otherwise, set <var title="">node</var> to the single
  2082   <a href="#concept-node" title="concept-node">node</a> <var title="">nodes</var> contains.
  2083 </ol>
  2084 
  2085 
  2086 <p>The
  2087 <dfn id="dom-rootnode-prepend" title="dom-RootNode-prepend"><code>prepend(<var>nodes</var>)</code></dfn>
  2088 method must run these steps:
  2089 
  2090 <ol>
  2091  <li>Run the <a href="#mutation-method-macro">mutation method macro</a>.
  2092 
  2093  <li><p><a href="#concept-node-pre-insert" title="concept-node-pre-insert">Pre-insert</a>
  2094  <var title="">node</var> into the <a href="#context-object">context object</a> before the
  2095  <a href="#context-object">context object</a>'s
  2096  <a href="#concept-tree-first-child" title="concept-tree-first-child">first child</a>.
  2097 </ol>
  2098 
  2099 <p>The
  2100 <dfn id="dom-rootnode-append" title="dom-RootNode-append"><code>append(<var>nodes</var>)</code></dfn>
  2101 method must run these steps:
  2102 
  2103 <ol>
  2104  <li>Run the <a href="#mutation-method-macro">mutation method macro</a>.
  2105 
  2106  <li><p><a href="#concept-node-append" title="concept-node-append">Append</a>
  2107  <var title="">node</var> to the <a href="#context-object">context object</a>.
  2108 </ol>
  2109 
  2110 
  2111 <p>The
  2112 <dfn id="dom-childnode-before" title="dom-ChildNode-before"><code>before(<var>nodes</var>)</code></dfn>
  2113 method must run these steps:
  2114 
  2115 <ol>
  2116  <li><p>If the <a href="#context-object">context object</a> does not have a
  2117  <a href="#concept-tree-parent" title="concept-tree-parent">parent</a>, terminate these steps.
  2118 
  2119  <li>Run the <a href="#mutation-method-macro">mutation method macro</a>.
  2120 
  2121  <li><p><a href="#concept-node-pre-insert" title="concept-node-pre-insert">Pre-insert</a>
  2122  <var title="">node</var> into the <a href="#context-object">context object</a>'s
  2123  <a href="#concept-tree-parent" title="concept-tree-parent">parent</a> before the
  2124  <a href="#context-object">context object</a>.
  2125 </ol>
  2126 
  2127 <p>The
  2128 <dfn id="dom-childnode-after" title="dom-ChildNode-after"><code>after(<var>nodes</var>)</code></dfn>
  2129 method must run these steps:
  2130 
  2131 <ol>
  2132  <li><p>If the <a href="#context-object">context object</a> does not have a
  2133  <a href="#concept-tree-parent" title="concept-tree-parent">parent</a>, terminate these steps.
  2134 
  2135  <li>Run the <a href="#mutation-method-macro">mutation method macro</a>.
  2136 
  2137  <li><p><a href="#concept-node-pre-insert" title="concept-node-pre-insert">Pre-insert</a>
  2138  <var title="">node</var> into the <a href="#context-object">context object</a>'s
  2139  <a href="#concept-tree-parent" title="concept-tree-parent">parent</a> before the
  2140  <a href="#context-object">context object</a>'s
  2141  <a href="#concept-tree-next-sibling" title="concept-tree-next-sibling">next sibling</a>.
  2142 </ol>
  2143 
  2144 <p>The
  2145 <dfn id="dom-childnode-replace" title="dom-ChildNode-replace"><code>replace(<var>nodes</var>)</code></dfn>
  2146 method must run these steps:
  2147 
  2148 <ol>
  2149  <li><p>If the <a href="#context-object">context object</a> does not have a
  2150  <a href="#concept-tree-parent" title="concept-tree-parent">parent</a>, terminate these steps.
  2151 
  2152  <li>Run the <a href="#mutation-method-macro">mutation method macro</a>.
  2153 
  2154  <li><p><a href="#concept-node-replace" title="concept-node-replace">Replace</a> the
  2155  <a href="#context-object">context object</a> with <var title="">node</var> within the
  2156  <a href="#context-object">context object</a>'s
  2157  <a href="#concept-tree-parent" title="concept-tree-parent">parent</a>.
  2158 </ol>
  2159 
  2160 <p>The
  2161 <dfn id="dom-childnode-remove" title="dom-ChildNode-remove"><code>remove()</code></dfn>
  2162 method must run these steps:
  2163 
  2164 <ol>
  2165  <li><p>If the <a href="#context-object">context object</a> does not have a
  2166  <a href="#concept-tree-parent" title="concept-tree-parent">parent</a>, terminate these steps.
  2167 
  2168  <li><p><a href="#concept-node-remove" title="concept-node-remove">Remove</a> the
  2169  <a href="#context-object">context object</a> from the
  2170  <a href="#context-object">context object</a>'s
  2171  <a href="#concept-tree-parent" title="concept-tree-parent">parent</a>.
  2172 </ol>
  2173 
  2174 
  2175 <h4 id="legacy-mutation-methods"><span class="secno">5.2.3 </span>Legacy mutation methods</h4>
  2176 
  2177 <p>The
  2178 <dfn id="dom-node-insertbefore" title="dom-Node-insertBefore"><code>insertBefore(<var>node</var>, <var>child</var>)</code></dfn>
  2179 method must return the result of
  2180 <a href="#concept-node-pre-insert" title="concept-node-pre-insert">pre-inserting</a>
  2181 <var title="">node</var> into the <a href="#context-object">context object</a> before
  2182 <var title="">child</var>.
  2183 
  2184 <p>The
  2185 <dfn id="dom-node-appendchild" title="dom-Node-appendChild"><code>appendChild(<var>node</var>)</code></dfn>
  2186 method must return the result of
  2187 <a href="#concept-node-append" title="concept-node-append">appending</a> <var title="">node</var> to
  2188 the <a href="#context-object">context object</a>.
  2189 
  2190 <p>The
  2191 <dfn id="dom-node-replacechild" title="dom-Node-replaceChild"><code>replaceChild(<var>node</var>, <var>child</var>)</code></dfn>
  2192 method must return the result of
  2193 <a href="#concept-node-replace" title="concept-node-replace">replacing</a> <var title="">child</var>
  2194 with <var title="">node</var> within the <a href="#context-object">context object</a>.
  2195 
  2196 <p>The
  2197 <dfn id="dom-node-removechild" title="dom-Node-removeChild"><code>removeChild(<var>child</var>)</code></dfn>
  2198 method must return the result of
  2199 <a href="#concept-node-pre-remove" title="concept-node-pre-remove">pre-removing</a>
  2200 <var title="">child</var> from the <a href="#context-object">context object</a>.
  2201 
  2202 
  2203 <h3 id="mutation-observers"><span class="secno">5.3 </span>Mutation observers</h3>
  2204 
  2205 <p>Each <i title="">scripting environment</i> has an associated list of
  2206 <code><a href="#mutationobserver">MutationObserver</a></code> objects which is initially empty. To
  2207 <dfn id="concept-mo-invoke" title="concept-MO-invoke">invoke</dfn> <code><a href="#mutationobserver">MutationObserver</a></code>
  2208 objects, run these steps:
  2209 
  2210 <ol>
  2211  <li><p>Let <var title="">notify list</var> be a copy of
  2212  <i title="">scripting environment</i>'s list of <code><a href="#mutationobserver">MutationObserver</a></code>
  2213  objects.
  2214 
  2215  <li>
  2216   <p>For each <code><a href="#mutationobserver">MutationObserver</a></code> object <var title="">mo</var>
  2217   in <var title="">notify list</var>, run these substeps:
  2218 
  2219   <ol>
  2220    <li><p>Let <var title="">queue</var> be a copy of <var title="">mo</var>'s
  2221    <a href="#concept-mo-queue" title="concept-MO-queue">record queue</a>.
  2222 
  2223    <li><p>Empty <var title="">mo</var>'s
  2224    <a href="#concept-mo-queue" title="concept-MO-queue">record queue</a>.
  2225 
  2226    <li><p>Remove all
  2227    <a href="#transient-registered-observer" title="transient registered observer">transient registered observers</a>
  2228    whose <b>observer</b> is <var title="">mo</var>.
  2229 
  2230    <li><p>If <var title="">queue</var> is non-empty, invoke
  2231    <var title="">mo</var>'s <a href="#concept-mo-callback" title="concept-MO-callback">callback</a>
  2232    with <var title="">queue</var> as first argument, and
  2233    <var title="">mo</var> (itself) as second argument and
  2234    <a class="external" data-anolis-spec="webidl" href="http://dev.w3.org/2006/webapi/WebIDL/#dfn-callback-this-value">callback this value</a>.
  2235   </ol>
  2236 
  2237  <li><p><p>If any <code><a href="#mutationobserver">MutationObserver</a></code> object in
  2238  <i title="">scripting environment</i>'s list of <code><a href="#mutationobserver">MutationObserver</a></code>
  2239  objects has a non-empty <a href="#concept-mo-queue" title="concept-MO-queue">record queue</a> at
  2240  this point, run these steps again (indeed, all of them).
  2241 </ol>
  2242 
  2243 <p class="note">The DOM standard does not define the
  2244 <i title="">scripting environment</i> nor its scope. The HTML standard defines
  2245 how this concept integrates with the rest of the platform as well as when
  2246 <a href="#concept-mo-invoke" title="concept-MO-invoke">invoke</a> is invoked. This somewhat
  2247 artificial  boundary is made to prevent a dependency from DOM on HTML.
  2248 <a class="informative" href="#refsHTML">[HTML]</a>
  2249 
  2250 <hr>
  2251 
  2252 <p>Each <a href="#concept-node" title="concept-node">node</a> has an associated list of
  2253 <a href="#registered-observer" title="registered observer">registered observers</a>.
  2254 <!-- XXX also mention this in the <code>Node</code> section non-normatively? -->
  2255 
  2256 <p>A <dfn id="registered-observer">registered observer</dfn> consists of an <b>observer</b> (a
  2257 <code><a href="#mutationobserver">MutationObserver</a></code> object) and <b>options</b> (a
  2258 <code><a href="#mutationobserverinit">MutationObserverInit</a></code> dictionary). A
  2259 <dfn id="transient-registered-observer">transient registered observer</dfn> is a specific type of
  2260 <a href="#registered-observer">registered observer</a>.
  2261 
  2262 
  2263 <h4 id="interface-mutationobserver"><span class="secno">5.3.1 </span>Interface <code><a href="#mutationobserver">MutationObserver</a></code></h4>
  2264 
  2265 <pre class="idl">[<a href="#dom-mutationobserver" title="dom-MutationObserver">Constructor</a>(<a href="#mutationcallback">MutationCallback</a> <var>callback</var>)]
  2266 interface <dfn id="mutationobserver">MutationObserver</dfn> {
  2267   void <a href="#dom-mutationobserver-observe" title="dom-MutationObserver-observe">observe</a>(<a href="#node">Node</a> <var>target</var>, <a href="#mutationobserverinit">MutationObserverInit</a> <var>options</var>);
  2268   void <a href="#dom-mutationobserver-disconnect" title="dom-MutationObserver-disconnect">disconnect</a>();
  2269   sequence&lt;<a href="#mutationrecord">MutationRecord</a>&gt; <a href="#dom-mutationobserver-takerecords" title="dom-MutationObserver-takeRecords">takeRecords</a>();
  2270 };
  2271 
  2272 callback <dfn id="mutationcallback">MutationCallback</dfn> = void (sequence&lt;<a href="#mutationrecord">MutationRecord</a>&gt; <var>mutations</var>, <a href="#mutationobserver">MutationObserver</a> <var>observer</var>);
  2273 
  2274 dictionary <dfn id="mutationobserverinit">MutationObserverInit</dfn> {
  2275   boolean <span title="dom-MutationObserverInit-childList">childList</span> = false;
  2276   boolean <span title="dom-MutationObserverInit-attributes">attributes</span> = false;
  2277   boolean <span title="dom-MutationObserverInit-characterData">characterData</span> = false;
  2278   boolean <span title="dom-MutationObserverInit-subtree">subtree</span> = false;
  2279   boolean <span title="dom-MutationObserverInit-attributeOldValue">attributeOldValue</span> = false;
  2280   boolean <span title="dom-MutationObserverInit-characterDataOldValue">characterDataOldValue</span> = false;
  2281   sequence&lt;DOMString&gt; <span title="dom-MutationObserverInit-attributeFilter">attributeFilter</span>;
  2282 };</pre>
  2283 
  2284 <p>A <code><a href="#mutationobserver">MutationObserver</a></code> object can be used to observe mutations
  2285 to the <a href="#concept-tree" title="concept-tree">tree</a> of
  2286 <a href="#concept-node" title="concept-node">nodes</a>.
  2287 
  2288 <p>Each <code><a href="#mutationobserver">MutationObserver</a></code> object has these associated concepts:
  2289 <ul>
  2290  <li><p>A <dfn id="concept-mo-callback" title="concept-MO-callback">callback</dfn> set on creation.
  2291  <li><p>A list of <a href="#concept-node" title="concept-node">nodes</a> on which it is a <a href="#registered-observer">registered observer</a>'s <b>observer</b> that is initially empty.
  2292  <li><p>A list of <code><a href="#mutationrecord">MutationRecord</a></code> objects called the
  2293  <dfn id="concept-mo-queue" title="concept-MO-queue">record queue</dfn> that is initially empty.
  2294 </ul>
  2295 
  2296 <dl class="domintro">
  2297  <dt><code>var <var title="">observer</var> = new <a href="#dom-mutationobserver" title="dom-MutationObserver">MutationObserver</a>(<var title="">callback</var>)</code>
  2298  <dd><p>Constructs a <code><a href="#mutationobserver">MutationObserver</a></code> object and sets its
  2299  <a href="#concept-mo-callback" title="concept-MO-callback">callback</a> to
  2300  <var title="">callback</var>. The <var title="">callback</var> is invoked with a
  2301  list of <code><a href="#mutationrecord">MutationRecord</a></code> objects as first argument and the
  2302  constructed <code><a href="#mutationobserver">MutationObserver</a></code> object as second argument. It is
  2303  invoked after <a href="#concept-node" title="concept-node">nodes</a> registered with the
  2304  <code title="dom-MutationObserver-observe"><a href="#dom-mutationobserver-observe">observe()</a></code> method, are
  2305  mutated.
  2306 
  2307  <dt><code><var title="">observer</var> . <a href="#dom-mutationobserver-observe" title="dom-MutationObserver-observe">observe</a>(<var title="">target</var>, <var title="">options</var>)</code>
  2308  <dd>
  2309   <p>Instructs the user agent to observe a given <var title="">target</var>
  2310   (a <a href="#concept-node" title="concept-node">node</a>) and report any mutations based on
  2311   the criteria given by <var title="">options</var> (an object).
  2312 
  2313   <p>The <var title="">options</var> argument allows for setting mutation
  2314   observation options via object members. These are the object members that
  2315   can be used:
  2316 
  2317   <dl>
  2318    <dt><code title="dom-MutationObserverInit-childList">childList</code>
  2319    <dd><p>Set to true if mutations to <var title="">target</var>'s
  2320    <a href="#concept-tree-child" title="concept-tree-child">children</a> are to be observed.
  2321 
  2322    <dt><code title="dom-MutationObserverInit-attributes">attributes</code>
  2323    <dd><p>Set to true if mutations to <var title="">target</var>'s
  2324    <a href="#concept-attribute" title="concept-attribute">attributes</a> are to be observed.
  2325 
  2326    <dt><code title="dom-MutationObserverInit-characterData">characterData</code>
  2327    <dd><p>Set to true if mutations to <var title="">target</var>'s
  2328    <a href="#concept-cd-data" title="concept-CD-data">data</a> are to be observed.
  2329 
  2330    <dt><code title="dom-MutationObserverInit-subtree">subtree</code>
  2331    <dd><p>Set to true if mutations to not just <var title="">target</var>, but
  2332    also <var title="">target</var>'s
  2333    <a href="#concept-tree-descendant" title="concept-tree-descendant">descendants</a> are to be
  2334    observed.
  2335 
  2336    <dt><code title="dom-MutationObserverInit-attributeOldValue">attributeOldValue</code>
  2337    <dd><p>Set to true if
  2338    <code title="dom-MutationObserverInit-attributes">attributes</code> is set
  2339    to true and <var title="">target</var>'s
  2340    <a href="#concept-attribute" title="concept-attribute">attribute</a>
  2341    <a href="#concept-attribute-value" title="concept-attribute-value">value</a> before the mutation
  2342    needs to be recorded.
  2343 
  2344    <dt><code title="dom-MutationObserverInit-characterDataOldValue">characterDataOldValue</code>
  2345    <dd><p>Set to true if
  2346    <code title="dom-MutationObserverInit-characterData">characterData</code>
  2347    is set to true and <var title="">target</var>'s
  2348    <a href="#concept-cd-data" title="concept-CD-data">data</a> before the mutation
  2349    needs to be recorded.
  2350 
  2351    <dt><code title="dom-MutationObserverInit-attributeFilter">attributeFilter</code>
  2352    <dd><p>Set to a list of <a href="#concept-attribute" title="concept-attribute">attribute</a>
  2353    <a href="#concept-attribute-local-name" title="concept-attribute-local-name">local names</a> (without
  2354    <a href="#concept-attribute-namespace" title="concept-attribute-namespace">namespace</a>) if not all
  2355    <a href="#concept-attribute" title="concept-attribute">attribute</a> mutations need to be
  2356    observed.
  2357   </dl>
  2358 
  2359  <dt><code><var title="">observer</var> . <a href="#dom-mutationobserver-disconnect" title="dom-MutationObserver-disconnect">disconnect</a>()</code>
  2360  <dd><p>Stops the <var title="">observer</var> from observing any mutations.
  2361  Until the <code title="dom-MutationObserver-observe"><a href="#dom-mutationobserver-observe">observe()</a></code> method
  2362  is used again, <var title="">observer</var>'s
  2363  <a href="#concept-mo-callback" title="concept-MO-callback">callback</a> will not be invoked.
  2364 
  2365  <dt><code><var title="">observer</var> . <a href="#dom-mutationobserver-takerecords" title="dom-MutationObserver-takeRecords">takeRecords</a>()</code>
  2366  <dd><p>Empties the <a href="#concept-mo-queue" title="concept-MO-queue">record queue</a> and
  2367  returns what was in there.
  2368 </dl>
  2369 
  2370 <p>The
  2371 <dfn id="dom-mutationobserver" title="dom-MutationObserver"><code>MutationObserver(<var>callback</var>)</code></dfn>
  2372 constructor must create a new <code><a href="#mutationobserver">MutationObserver</a></code> object with
  2373 <a href="#concept-mo-callback" title="concept-MO-callback">callback</a> set to <var>callback</var>,
  2374 append it to the <i title="">scripting environment</i>'s list of
  2375 <code><a href="#mutationobserver">MutationObserver</a></code> objects, and then return it.
  2376 
  2377 <p>The
  2378 <dfn id="dom-mutationobserver-observe" title="dom-MutationObserver-observe"><code>observe(<var title="">target</var>, <var title="">options</var>)</code></dfn>
  2379 method must run these steps:
  2380 
  2381 <ol>
  2382  <li>
  2383   <p>Run these substeps, with <var title="">options</var> as the <a href="#context-object">context object</a>:
  2384   <ol>
  2385    <li><p>If neither
  2386    <code title="dom-MutationObserverInit-childList">childList</code>,
  2387    <code title="dom-MutationObserverInit-attributes">attributes</code>, nor
  2388    <code title="dom-MutationObserverInit-characterData">characterData</code>
  2389    is true, <a href="#concept-throw" title="concept-throw">throw</a> a "<code><a href="#syntaxerror">SyntaxError</a></code>"
  2390    and terminate these steps.
  2391 
  2392    <li><p>If <code title="dom-MutationObserverInit-attributeOldValue">attributeOldValue</code> is true and
  2393    <code title="dom-MutationObserverInit-attributes">attributes</code> is not true,
  2394    <a href="#concept-throw" title="concept-throw">throw</a> a "<code><a href="#syntaxerror">SyntaxError</a></code>" and terminate these steps.
  2395 
  2396    <li><p>If <code title="dom-MutationObserverInit-attributeFilter">attributeFilter</code>
  2397    is a non-empty array and
  2398    <code title="dom-MutationObserverInit-attributes">attributes</code> is not true,
  2399    <a href="#concept-throw" title="concept-throw">throw</a> a "<code><a href="#syntaxerror">SyntaxError</a></code>" and terminate these steps.
  2400 
  2401    <li><p>If <code title="dom-MutationObserverInit-characterDataOldValue">characterDataOldValue</code>
  2402    is true and <code title="dom-MutationObserverInit-characterData">characterData</code> is not true,
  2403    <a href="#concept-throw" title="concept-throw">throw</a> a "<code><a href="#syntaxerror">SyntaxError</a></code>" and terminate these steps.
  2404   </ol>
  2405 
  2406  <li><p>If <var title="">target</var>'s list of
  2407  <a href="#registered-observer" title="registered observer">registered observers</a> already
  2408  includes a <a href="#registered-observer">registered observer</a> associated with
  2409  the <a href="#context-object">context object</a>, replace that
  2410  <a href="#registered-observer">registered observer</a>'s <b>options</b> with <var title="">options</var>.
  2411 
  2412  <li><p>Otherwise, add a new <a href="#registered-observer">registered observer</a> to
  2413  <var title="">target</var>'s list of
  2414  <a href="#registered-observer" title="registered observer">registered observers</a> with the
  2415  <a href="#context-object">context object</a> as the <b>observer</b> and <var title="">options</var> as the <b>options</b>,
  2416  and add <var title="">target</var> to <a href="#context-object">context object</a>'s list of <a href="#concept-node" title="concept-node">nodes</a> on which it is registered.
  2417 </ol>
  2418 
  2419 <p>The
  2420 <dfn id="dom-mutationobserver-disconnect" title="dom-MutationObserver-disconnect"><code>disconnect()</code></dfn>
  2421 method must, for each <a href="#concept-node" title="concept-node">node</a>
  2422 <var title="">node</var> in the <a href="#context-object">context object</a>'s list of
  2423 <a href="#concept-node" title="concept-node">nodes</a>, remove any
  2424 <a href="#registered-observer">registered observer</a> on <var title="">node</var>
  2425 for which the <a href="#context-object">context object</a> is the <b>observer</b>, and also
  2426 empty <a href="#context-object">context object</a>'s
  2427 <a href="#concept-mo-queue" title="concept-MO-queue">record queue</a>.
  2428 
  2429 <p>The
  2430 <dfn id="dom-mutationobserver-takerecords" title="dom-MutationObserver-takeRecords"><code>takeRecords()</code></dfn>
  2431 method must return a copy of the
  2432 <a href="#concept-mo-queue" title="concept-MO-queue">record queue</a> and then empty the
  2433 <a href="#concept-mo-queue" title="concept-MO-queue">record queue</a>.
  2434 
  2435 
  2436 <h4 id="queuing-a-mutation-record"><span class="secno">5.3.2 </span>Queuing a mutation record</h4>
  2437 
  2438 <p>To <dfn id="queue-a-mutation-record">queue a mutation record</dfn> of <var title="">type</var> for
  2439 <var title="">target</var> with one or more of (depends on
  2440 <var title="">type</var>) name <var title="">name</var>, namespace
  2441 <var title="">namespace</var>, oldValue <var title="">oldValue</var>, addedNodes
  2442 <var title="">addedNodes</var>, removedNodes <var title="">removedNodes</var>,
  2443 previousSibling <var title="">previousSibling</var>, and nextSibling
  2444 <var title="">nextSibling</var>, run these steps:
  2445 
  2446 <ol>
  2447  <li><p>Let <var title="">record</var> be a new <code><a href="#mutationrecord">MutationRecord</a></code>
  2448  object with its <code title="dom-MutationRecord-type"><a href="#dom-mutationrecord-type">type</a></code> set to
  2449  <var title="">type</var> and
  2450  <code title="dom-MutationRecord-target"><a href="#dom-mutationrecord-target">target</a></code> set to
  2451  <var title="">target</var>.
  2452 
  2453  <li><p>If <var title="">name</var> and <var title="">namespace</var> are given,
  2454  set <var title="">record</var>'s
  2455  <code title="dom-MutationRecord-attributeName"><a href="#dom-mutationrecord-attributename">attributeName</a></code> to
  2456  <var title="">name</var>, and <var title="">record</var>'s
  2457  <code title="dom-MutationRecord-attributeNamespace"><a href="#dom-mutationrecord-attributenamespace">attributeNamespace</a></code>
  2458  to <var title="">namespace</var>.
  2459 
  2460  <li><p>If <var title="">addedNodes</var>, <var title="">removedNodes</var>,
  2461  <var title="">previousSibling</var>, and <var title="">nextSibling</var> are
  2462  given, set <var title="">record</var>'s
  2463  <code title="dom-MutationRecord-addedNodes"><a href="#dom-mutationrecord-addednodes">addedNodes</a></code> to
  2464  <var title="">addedNodes</var>, <var title="">record</var>'s
  2465  <code title="dom-MutationRecord-removedNodes"><a href="#dom-mutationrecord-removednodes">removedNodes</a></code> to
  2466  <var title="">removedNodes</var>, <var title="">record</var>'s
  2467  <code title="dom-MutationRecord-previousSibling"><a href="#dom-mutationrecord-previoussibling">previousSibling</a></code> to
  2468  <var title="">previousSibling</var>, and <var title="">record</var>'s
  2469  <code title="dom-MutationRecord-nextSibling"><a href="#dom-mutationrecord-nextsibling">nextSibling</a></code> to
  2470  <var title="">nextSibling</var>.
  2471 
  2472  <li><p>Let <var title="">interested observers</var> be an initially empty set
  2473  of <code><a href="#mutationobserver">MutationObserver</a></code> objects optionally paired with a string.
  2474 
  2475  <li><p>Let <var title="">nodes</var> be the
  2476  <a href="#concept-tree-inclusive-ancestor" title="concept-tree-inclusive-ancestor">inclusive ancestors</a> of
  2477  <var title="">target</var>.
  2478 
  2479  <li>
  2480   <p>Then, for each <var title="">node</var> in <var title="">nodes</var>, and
  2481   then for each <var title="">registered observer</var> (with
  2482   <var title="">registered observer</var>'s <b title="">options</b> as
  2483   <var title="">options</var>) in <var title="">node</var>'s list of
  2484   <a href="#registered-observer" title="registered observer">registered observers</a>:
  2485 
  2486   <ol>
  2487    <li><p>If <var title="">node</var> is not <var title="">target</var> and
  2488    <var title="">options</var>'s <code title="">subtree</code> is false, continue.
  2489 
  2490    <li><p>If <var title="">type</var> is "<code title="">attributes</code>" and
  2491    <var title="">options</var>'s <code title="">attributes</code> is false,
  2492    continue.
  2493 
  2494    <li><p>If <var title="">type</var> is "<code title="">attributes</code>",
  2495    <var title="">options</var>'s <code title="">attributeFilter</code> is
  2496    non-empty, and either <var title="">options</var>'s
  2497    <code title="">attributeFilter</code> does not contain <var title="">name</var>
  2498    or <var title="">namespace</var> is non-null, continue.
  2499 
  2500    <li><p>If <var title="">type</var> is "<code title="">characterData</code>" and
  2501    <var title="">options</var>'s <code title="">characterData</code> is false,
  2502    continue.
  2503 
  2504    <li><p>If <var title="">type</var> is "<code title="">childList</code>" and
  2505    <var title="">options</var>'s <code title="">childList</code> is false,
  2506    continue.
  2507 
  2508    <li><p>If <var title="">registered observer</var>'s <b title="">observer</b> is
  2509    not in <var title="">interested observers</var>, append
  2510    <var title="">registered observer</var>'s <b title="">observer</b> to
  2511    <var title="">interested observers</var>.
  2512 
  2513    <li><p>If either <var title="">type</var> is "<code title="">attributes</code>"
  2514    and <var title="">options</var>'s <code>attributeOldValue</code> is true, or
  2515    <var title="">type</var> is "<code title="">characterData</code>" and
  2516    <var title="">options</var>'s <code>characterDataOldValue</code> is true,
  2517    set the paired string of
  2518    <var title="">registered observer</var>'s <b title="">observer</b> in
  2519    <var title="">interested observers</var> to <var title="">oldValue</var>.
  2520   </ol>
  2521 
  2522  <li>
  2523   <p>Then, for each <var title="">observer</var> in
  2524   <var title="">interested observers</var>:
  2525 
  2526   <ol>
  2527    <li><p>If <var title="">observer</var> has a paired string,
  2528    set <var title="">record</var>'s <code title="">oldValue</code> to
  2529    <var title="">observer</var>'s paired string.
  2530 
  2531    <li><p>Append <var title="">record</var> to <var title="">observer</var>'s
  2532    <a href="#concept-mo-queue" title="concept-MO-queue">record queue</a>.
  2533   </ol>
  2534 </ol>
  2535 
  2536 
  2537 <h4 id="interface-mutationrecord"><span class="secno">5.3.3 </span>Interface <code><a href="#mutationrecord">MutationRecord</a></code></h4>
  2538 
  2539 <pre class="idl">interface <dfn id="mutationrecord">MutationRecord</dfn> {
  2540   readonly attribute DOMString <a href="#dom-mutationrecord-type" title="dom-MutationRecord-type">type</a>;
  2541   readonly attribute <a href="#node">Node</a> <a href="#dom-mutationrecord-target" title="dom-MutationRecord-target">target</a>;
  2542   readonly attribute <a href="#nodelist">NodeList</a> <a href="#dom-mutationrecord-addednodes" title="dom-MutationRecord-addedNodes">addedNodes</a>;
  2543   readonly attribute <a href="#nodelist">NodeList</a> <a href="#dom-mutationrecord-removednodes" title="dom-MutationRecord-removedNodes">removedNodes</a>;
  2544   readonly attribute <a href="#node">Node</a>? <a href="#dom-mutationrecord-previoussibling" title="dom-MutationRecord-previousSibling">previousSibling</a>;
  2545   readonly attribute <a href="#node">Node</a>? <a href="#dom-mutationrecord-nextsibling" title="dom-MutationRecord-nextSibling">nextSibling</a>;
  2546   readonly attribute DOMString? <a href="#dom-mutationrecord-attributename" title="dom-MutationRecord-attributeName">attributeName</a>;
  2547   readonly attribute DOMString? <a href="#dom-mutationrecord-attributenamespace" title="dom-MutationRecord-attributeNamespace">attributeNamespace</a>;
  2548   readonly attribute DOMString? <a href="#dom-mutationrecord-oldvalue" title="dom-MutationRecord-oldValue">oldValue</a>;
  2549 };</pre>
  2550 
  2551 <dl class="domintro">
  2552  <dt><code><var title="">record</var> . <a href="#dom-mutationrecord-type" title="dom-MutationRecord-type">type</a></code>
  2553  <dd><p>Returns "<code title="">attributes</code>" if it was an
  2554  <a href="#concept-attribute" title="concept-attribute">attribute</a> mutation.
  2555  "<code title="">characterData</code>" if it was a mutation to a
  2556  <code><a href="#characterdata">CharacterData</a></code> <a href="#concept-node" title="concept-node">node</a>. And
  2557  "<code title="">childList</code>" if it was a mutation to the
  2558  <a href="#concept-tree" title="concept-tree">tree</a> of
  2559  <a href="#concept-node" title="concept-node">nodes</a>.
  2560 
  2561  <dt><code><var title="">record</var> . <a href="#dom-mutationrecord-target" title="dom-MutationRecord-target">target</a></code>
  2562  <dd><p>Returns the <a href="#concept-node" title="concept-node">node</a> the mutation
  2563  affected, depending on the <code title="dom-MutationRecord-type"><a href="#dom-mutationrecord-type">type</a></code>.
  2564  For "<code title="">attributes</code>", it is the
  2565  <a href="#concept-element" title="concept-element">element</a> whose
  2566  <a href="#concept-attribute" title="concept-attribute">attribute</a> changed. For
  2567  "<code title="">characterData</code>", it is the <code><a href="#characterdata">CharacterData</a></code>
  2568  <a href="#concept-node" title="concept-node">node</a>. For "<code title="">childList</code>",
  2569  it is the  <a href="#concept-node" title="concept-node">node</a> whose
  2570  <a href="#concept-tree-child" title="concept-tree-child">children</a> changed.
  2571 
  2572  <dt><code><var title="">record</var> . <a href="#dom-mutationrecord-addednodes" title="dom-MutationRecord-addedNodes">addedNodes</a></code>
  2573  <dt><code><var title="">record</var> . <a href="#dom-mutationrecord-removednodes" title="dom-MutationRecord-removedNodes">removedNodes</a></code>
  2574  <dd><p>Return the <a href="#concept-node" title="concept-node">nodes</a> added and removed
  2575  respectively.
  2576 
  2577  <dt><code><var title="">record</var> . <a href="#dom-mutationrecord-previoussibling" title="dom-MutationRecord-previousSibling">previousSibling</a></code>
  2578  <dt><code><var title="">record</var> . <a href="#dom-mutationrecord-nextsibling" title="dom-MutationRecord-nextSibling">nextSibling</a></code>
  2579  <dd><p>Return the <a href="#concept-tree-previous-sibling" title="concept-tree-previous-sibling">previous</a>
  2580  and <a href="#concept-tree-next-sibling" title="concept-tree-next-sibling">next sibling</a> respectively
  2581  of the added or removed <a href="#concept-node" title="concept-node">nodes</a>, or null
  2582  otherwise.
  2583 
  2584  <dt><code><var title="">record</var> . <a href="#dom-mutationrecord-attributename" title="dom-MutationRecord-attributeName">attributeName</a></code>
  2585  <dd><p>Returns the
  2586  <a href="#concept-attribute-local-name" title="concept-attribute-local-name">local name</a> of the
  2587  changed <a href="#concept-attribute" title="concept-attribute">attribute</a>, or null otherwise.
  2588 
  2589  <dt><code><var title="">record</var> . <a href="#dom-mutationrecord-attributenamespace" title="dom-MutationRecord-attributeNamespace">attributeNamespace</a></code>
  2590  <dd><p>Returns the <a href="#concept-attribute-namespace" title="concept-attribute-namespace">namespace</a> of the
  2591  changed <a href="#concept-attribute" title="concept-attribute">attribute</a>, or null otherwise.
  2592 
  2593  <dt><code><var title="">record</var> . <a href="#dom-mutationrecord-oldvalue" title="dom-MutationRecord-oldValue">oldValue</a></code>
  2594  <dd><p>The return value depends on
  2595  <code title="dom-MutationRecord-type"><a href="#dom-mutationrecord-type">type</a></code>. For
  2596  "<code title="">attributes</code>", it is the
  2597  <a href="#concept-attribute-value" title="concept-attribute-value">value</a> of the
  2598  changed <a href="#concept-attribute" title="concept-attribute">attribute</a> before the change.
  2599  For "<code title="">characterData</code>", it is the
  2600  <a href="#concept-cd-data" title="concept-CD-data">data</a> of the changed
  2601  <a href="#concept-node" title="concept-node">node</a> before the change. For
  2602  "<code title="">childList</code>", it is null.
  2603 </dl>
  2604 
  2605 <p>The <dfn id="dom-mutationrecord-type" title="dom-MutationRecord-type"><code>type</code></dfn> and
  2606 <dfn id="dom-mutationrecord-target" title="dom-MutationRecord-target"><code>target</code></dfn>
  2607 attributes must return the values they were initialized to.
  2608 
  2609 <p>The
  2610 <dfn id="dom-mutationrecord-addednodes" title="dom-MutationRecord-addedNodes"><code>addedNodes</code></dfn> and
  2611 <dfn id="dom-mutationrecord-removednodes" title="dom-MutationRecord-removedNodes"><code>removedNodes</code></dfn>
  2612 attributes must be return the values they were initialized to. Unless stated
  2613 otherwise, when a <code><a href="#mutationrecord">MutationRecord</a></code> object is created, they must
  2614 both be initialized to an empty <code><a href="#nodelist">NodeList</a></code>.
  2615 
  2616 <p>The
  2617 <dfn id="dom-mutationrecord-previoussibling" title="dom-MutationRecord-previousSibling"><code>previousSibling</code></dfn>,
  2618 <dfn id="dom-mutationrecord-nextsibling" title="dom-MutationRecord-nextSibling"><code>nextSibling</code></dfn>,
  2619 <dfn id="dom-mutationrecord-attributename" title="dom-MutationRecord-attributeName"><code>attributeName</code></dfn>,
  2620 <dfn id="dom-mutationrecord-attributenamespace" title="dom-MutationRecord-attributeNamespace"><code>attributeNamespace</code></dfn>, and
  2621 <dfn id="dom-mutationrecord-oldvalue" title="dom-MutationRecord-oldValue"><code>oldValue</code></dfn>
  2622 attributes must return the values they were initialized to. Unless stated
  2623 otherwise, when a <code><a href="#mutationrecord">MutationRecord</a></code> object is created, they must
  2624 be initialized to null.
  2625 
  2626 <h4 id="garbage-collection"><span class="secno">5.3.4 </span>Garbage collection</h4>
  2627 
  2628 <p><a href="#concept-node" title="concept-node">Nodes</a> have a strong reference to
  2629 <a href="#registered-observer" title="registered observer">registered observers</a> in their
  2630 list of <a href="#registered-observer" title="registered observer">registered observers</a>.
  2631 
  2632 <p><a href="#registered-observer" title="registered observer">Registered observers</a> in a
  2633 <a href="#concept-node" title="concept-node">node</a>'s list of
  2634 <a href="#registered-observer" title="registered observer">registered observers</a> have a weak
  2635 reference to the <a href="#concept-node" title="concept-node">node</a>.
  2636 
  2637 
  2638 <h3 id="interface-node"><span class="secno">5.4 </span>Interface <code><a href="#node">Node</a></code></h3>
  2639 <pre class="idl">interface <dfn id="node">Node</dfn> : <a href="#eventtarget">EventTarget</a> {
  2640   const unsigned short <a href="#dom-node-element_node" title="dom-Node-ELEMENT_NODE">ELEMENT_NODE</a> = 1;
  2641   const unsigned short <span title="dom-Node-ATTRIBUTE_NODE">ATTRIBUTE_NODE</span> = 2; // historical
  2642   const unsigned short <a href="#dom-node-text_node" title="dom-Node-TEXT_NODE">TEXT_NODE</a> = 3;
  2643   const unsigned short <span title="dom-Node-CDATA_SECTION_NODE">CDATA_SECTION_NODE</span> = 4; // historical
  2644   const unsigned short <span title="dom-Node-ENTITY_REFERENCE_NODE">ENTITY_REFERENCE_NODE</span> = 5; // historical
  2645   const unsigned short <span title="dom-Node-ENTITY_NODE">ENTITY_NODE</span> = 6; // historical
  2646   const unsigned short <a href="#dom-node-processing_instruction_node" title="dom-Node-PROCESSING_INSTRUCTION_NODE">PROCESSING_INSTRUCTION_NODE</a> = 7;
  2647   const unsigned short <a href="#dom-node-comment_node" title="dom-Node-COMMENT_NODE">COMMENT_NODE</a> = 8;
  2648   const unsigned short <a href="#dom-node-document_node" title="dom-Node-DOCUMENT_NODE">DOCUMENT_NODE</a> = 9;
  2649   const unsigned short <a href="#dom-node-document_type_node" title="dom-Node-DOCUMENT_TYPE_NODE">DOCUMENT_TYPE_NODE</a> = 10;
  2650   const unsigned short <a href="#dom-node-document_fragment_node" title="dom-Node-DOCUMENT_FRAGMENT_NODE">DOCUMENT_FRAGMENT_NODE</a> = 11;
  2651   const unsigned short <span title="dom-Node-NOTATION_NODE">NOTATION_NODE</span> = 12; // historical
  2652   readonly attribute unsigned short <a href="#dom-node-nodetype" title="dom-Node-nodeType">nodeType</a>;<!-- NodeExodus
  2653 
  2654   readonly attribute DOMString <span title=dom-Node-namespaceURI>namespaceURI</span>;
  2655   readonly attribute DOMString <span title=dom-Node-prefix>prefix</span>;
  2656   readonly attribute DOMString <span title=dom-Node-localName>localName</span>;-->
  2657   readonly attribute DOMString <a href="#dom-node-nodename" title="dom-Node-nodeName">nodeName</a>;
  2658 
  2659   readonly attribute DOMString? <a href="#dom-node-baseuri" title="dom-Node-baseURI">baseURI</a>;
  2660 
  2661   <!--AttrExodus
  2662   boolean <span title=dom-Node-hasAttributes>hasAttributes</span>();
  2663   readonly attribute <span>NamedNodeMap</span> <span title=dom-Node-attributes>attributes</span>;
  2664 
  2665   -->readonly attribute <a href="#document">Document</a>? <a href="#dom-node-ownerdocument" title="dom-Node-ownerDocument">ownerDocument</a>;
  2666   readonly attribute <a href="#node">Node</a>? <a href="#dom-node-parentnode" title="dom-Node-parentNode">parentNode</a>;
  2667   readonly attribute <a href="#element">Element</a>? <a href="#dom-node-parentelement" title="dom-Node-parentElement">parentElement</a>;
  2668   boolean <a href="#dom-node-haschildnodes" title="dom-Node-hasChildNodes">hasChildNodes</a>();
  2669   readonly attribute <a href="#nodelist">NodeList</a> <a href="#dom-node-childnodes" title="dom-Node-childNodes">childNodes</a>;
  2670   readonly attribute <a href="#node">Node</a>? <a href="#dom-node-firstchild" title="dom-Node-firstChild">firstChild</a>;
  2671   readonly attribute <a href="#node">Node</a>? <a href="#dom-node-lastchild" title="dom-Node-lastChild">lastChild</a>;
  2672   readonly attribute <a href="#node">Node</a>? <a href="#dom-node-previoussibling" title="dom-Node-previousSibling">previousSibling</a>;
  2673   readonly attribute <a href="#node">Node</a>? <a href="#dom-node-nextsibling" title="dom-Node-nextSibling">nextSibling</a>;
  2674 
  2675            attribute DOMString? <a href="#dom-node-nodevalue" title="dom-Node-nodeValue">nodeValue</a>;
  2676            attribute DOMString? <a href="#dom-node-textcontent" title="dom-Node-textContent">textContent</a>;
  2677   <a href="#node">Node</a> <a href="#dom-node-insertbefore" title="dom-Node-insertBefore">insertBefore</a>(<a href="#node">Node</a> <var title="">node</var>, <a href="#node">Node</a>? <var title="">child</var>);
  2678   <a href="#node">Node</a> <a href="#dom-node-appendchild" title="dom-Node-appendChild">appendChild</a>(<a href="#node">Node</a> <var title="">node</var>);
  2679   <a href="#node">Node</a> <a href="#dom-node-replacechild" title="dom-Node-replaceChild">replaceChild</a>(<a href="#node">Node</a> <var title="">node</var>, <a href="#node">Node</a> <var title="">child</var>);
  2680   <a href="#node">Node</a> <a href="#dom-node-removechild" title="dom-Node-removeChild">removeChild</a>(<a href="#node">Node</a> <var title="">child</var>);
  2681   void <a href="#dom-node-normalize" title="dom-Node-normalize">normalize</a>();
  2682 
  2683   <!-- IE10 Developer Preview and Chrome 18 dev default the parameter to false.
  2684   Firefox 13.0a1 and Opera Next 12.00 alpha make it required.  But for
  2685   importNode() we default to true, and true seems more useful, so for now we
  2686   require true.
  2687   --><a href="#node">Node</a> <a href="#dom-node-clonenode" title="dom-Node-cloneNode">cloneNode</a>(optional boolean <var title="">deep</var> = true);
  2688   boolean <a href="#dom-node-isequalnode" title="dom-Node-isEqualNode">isEqualNode</a>(<a href="#node">Node</a>? <var title="">node</var>);
  2689 
  2690   const unsigned short <a href="#dom-node-document_position_disconnected" title="dom-Node-DOCUMENT_POSITION_DISCONNECTED">DOCUMENT_POSITION_DISCONNECTED</a> = 0x01;
  2691   const unsigned short <a href="#dom-node-document_position_preceding" title="dom-Node-DOCUMENT_POSITION_PRECEDING">DOCUMENT_POSITION_PRECEDING</a> = 0x02;
  2692   const unsigned short <a href="#dom-node-document_position_following" title="dom-Node-DOCUMENT_POSITION_FOLLOWING">DOCUMENT_POSITION_FOLLOWING</a> = 0x04;
  2693   const unsigned short <a href="#dom-node-document_position_contains" title="dom-Node-DOCUMENT_POSITION_CONTAINS">DOCUMENT_POSITION_CONTAINS</a> = 0x08;
  2694   const unsigned short <a href="#dom-node-document_position_contained_by" title="dom-Node-DOCUMENT_POSITION_CONTAINED_BY">DOCUMENT_POSITION_CONTAINED_BY</a> = 0x10;
  2695   const unsigned short <a href="#dom-node-document_position_implementation_specific" title="dom-Node-DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC">DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC</a> = 0x20;
  2696   unsigned short <a href="#dom-node-comparedocumentposition" title="dom-Node-compareDocumentPosition">compareDocumentPosition</a>(<a href="#node">Node</a> <var title="">other</var>);
  2697   boolean <a href="#dom-node-contains" title="dom-Node-contains">contains</a>(<a href="#node">Node</a>? <var title="">other</var>);
  2698 
  2699   DOMString? <a href="#dom-node-lookupprefix" title="dom-Node-lookupPrefix">lookupPrefix</a>(DOMString? <var title="">namespace</var>);
  2700   DOMString? <a href="#dom-node-lookupnamespaceuri" title="dom-Node-lookupNamespaceURI">lookupNamespaceURI</a>(DOMString? <var title="">prefix</var>);
  2701   boolean <a href="#dom-node-isdefaultnamespace" title="dom-Node-isDefaultNamespace">isDefaultNamespace</a>(DOMString? <var title="">namespace</var>);
  2702 };</pre>
  2703 
  2704 <p class="note"><code><a href="#node">Node</a></code> is an abstract interface and does not exist
  2705 as <a href="#concept-node" title="concept-node">node</a>. It is used by all
  2706 <a href="#concept-node" title="concept-node">nodes</a> (<code><a href="#document">Document</a></code>,
  2707 <code><a href="#documentfragment">DocumentFragment</a></code>, <code><a href="#documenttype">DocumentType</a></code>,
  2708 <code><a href="#element">Element</a></code>, <code><a href="#text">Text</a></code>, <code><a href="#processinginstruction">ProcessingInstruction</a></code>,
  2709 and <code><a href="#comment">Comment</a></code>).
  2710 
  2711 <p>Each <a href="#concept-node" title="concept-node">node</a> has an associated
  2712 <dfn id="concept-node-document" title="concept-node-document">node document</dfn>, set upon creation,
  2713 that is a <a href="#concept-document" title="concept-document">document</a>.
  2714 
  2715 <p class="note">A <a href="#concept-node" title="concept-node">node</a>'s
  2716 <a href="#concept-node-document" title="concept-node-document">node document</a> can be changed by
  2717 the "<a href="#concept-node-adopt" title="concept-node-adopt">adopt</a>" algorithm.
  2718 
  2719 <p>Each <a href="#concept-node" title="concept-node">node</a> also has an associated
  2720 <dfn id="concept-node-base-url" title="concept-node-base-url">base URL</dfn>.
  2721 
  2722 <p class="note">Other specifications define the value of the
  2723 <a href="#concept-node-base-url" title="concept-node-base-url">base URL</a> and its observable
  2724 behavior. This specification solely defines the concept and the
  2725 <code title="dom-Node-baseURI"><a href="#dom-node-baseuri">baseURI</a></code> attribute.
  2726 
  2727 <hr>
  2728 
  2729 <dl class="domintro">
  2730  <dt><code><var title="">node</var> . <a href="#dom-node-nodetype" title="dom-Node-nodeType">nodeType</a></code>
  2731  <dd>
  2732   <p>Returns the type of <var title="">node</var>, represented by a number from the following list:</p>
  2733 
  2734   <dl>
  2735    <dt><code><a href="#node">Node</a> . <a href="#dom-node-element_node" title="dom-Node-ELEMENT_NODE">ELEMENT_NODE</a></code> (1)
  2736    <dd><var title="">node</var> is an
  2737    <a href="#concept-element" title="concept-element">element</a>.
  2738 
  2739    <dt><code><a href="#node">Node</a> . <a href="#dom-node-text_node" title="dom-Node-TEXT_NODE">TEXT_NODE</a></code> (3)
  2740    <dd><var title="">node</var> is a <code><a href="#text">Text</a></code>
  2741    <a href="#concept-node" title="concept-node">node</a>.
  2742 
  2743    <dt><code><a href="#node">Node</a> . <a href="#dom-node-processing_instruction_node" title="dom-Node-PROCESSING_INSTRUCTION_NODE">PROCESSING_INSTRUCTION_NODE</a></code> (7)
  2744    <dd><var title="">node</var> is a <code><a href="#processinginstruction">ProcessingInstruction</a></code>
  2745    <a href="#concept-node" title="concept-node">node</a>.
  2746 
  2747    <dt><code><a href="#node">Node</a> . <a href="#dom-node-comment_node" title="dom-Node-COMMENT_NODE">COMMENT_NODE</a></code> (8)
  2748    <dd><var title="">node</var> is a <code><a href="#comment">Comment</a></code>
  2749    <a href="#concept-node" title="concept-node">node</a>.
  2750 
  2751    <dt><code><a href="#node">Node</a> . <a href="#dom-node-document_node" title="dom-Node-DOCUMENT_NODE">DOCUMENT_NODE</a></code> (9)
  2752    <dd><var title="">node</var> is a
  2753    <a href="#concept-document" title="concept-document">document</a>.
  2754 
  2755    <dt><code><a href="#node">Node</a> . <a href="#dom-node-document_type_node" title="dom-Node-DOCUMENT_TYPE_NODE">DOCUMENT_TYPE_NODE</a></code> (10)
  2756    <dd><var title="">node</var> is a
  2757    <a href="#concept-doctype" title="concept-doctype">doctype</a>.
  2758 
  2759    <dt><code><a href="#node">Node</a> . <a href="#dom-node-document_fragment_node" title="dom-Node-DOCUMENT_FRAGMENT_NODE">DOCUMENT_FRAGMENT_NODE</a></code> (11)
  2760    <dd><var title="">node</var> is a <code><a href="#documentfragment">DocumentFragment</a></code>
  2761    <a href="#concept-node" title="concept-node">node</a>.
  2762   </dl>
  2763 
  2764  <dt><code><var title="">node</var> . <a href="#dom-node-nodename" title="dom-Node-nodeName">nodeName</a></code>
  2765  <dd>
  2766   <p>Returns a string appropriate for the type of <var title="">node</var>, as
  2767   follows:
  2768 
  2769   <dl>
  2770    <dt><code><a href="#element">Element</a></code>
  2771    <dd>Its <code title="dom-Element-tagName"><a href="#dom-element-tagname">tagName</a></code> attribute value.
  2772 
  2773    <dt><code><a href="#text">Text</a></code>
  2774    <dd>"<code title="">#text</code>".
  2775 
  2776    <dt><code><a href="#processinginstruction">ProcessingInstruction</a></code>
  2777    <dd>Its <a href="#concept-pi-target" title="concept-PI-target">target</a>.
  2778 
  2779    <dt><code><a href="#comment">Comment</a></code>
  2780    <dd>"<code title="">#comment</code>".
  2781 
  2782    <dt><code><a href="#document">Document</a></code>
  2783    <dd>"<code title="">#document</code>".
  2784 
  2785    <dt><code><a href="#documenttype">DocumentType</a></code>
  2786    <dd>Its <a href="#concept-doctype-name" title="concept-doctype-name">name</a>.
  2787 
  2788    <dt><code><a href="#documentfragment">DocumentFragment</a></code>
  2789    <dd>"<code title="">#document-fragment</code>".
  2790   </dl>
  2791 </dl>
  2792 
  2793 <p>The <dfn id="dom-node-nodetype" title="dom-Node-nodeType"><code>nodeType</code></dfn> attribute
  2794 must return the type of the node, which must be one of the following:
  2795 
  2796 <ul>
  2797  <li><dfn id="dom-node-element_node" title="dom-Node-ELEMENT_NODE"><code>ELEMENT_NODE</code></dfn> (1);
  2798 
  2799  <!--AttrExodus
  2800  <li><dfn title=dom-Node-ATTRIBUTE_NODE><code>ATTRIBUTE_NODE</code></dfn> (2, historical);
  2801  -->
  2802 
  2803  <li><dfn id="dom-node-text_node" title="dom-Node-TEXT_NODE"><code>TEXT_NODE</code></dfn> (3);
  2804 
  2805  <!-- XXX still questionable
  2806  <li><dfn title=dom-Node-CDATA_SECTION_NODE><code>CDATA_SECTION_NODE</code></dfn> (4, historical);
  2807  -->
  2808 
  2809  <li><dfn id="dom-node-processing_instruction_node" title="dom-Node-PROCESSING_INSTRUCTION_NODE"><code>PROCESSING_INSTRUCTION_NODE</code></dfn> (7);
  2810 
  2811  <li><dfn id="dom-node-comment_node" title="dom-Node-COMMENT_NODE"><code>COMMENT_NODE</code></dfn> (8);
  2812 
  2813  <li><dfn id="dom-node-document_node" title="dom-Node-DOCUMENT_NODE"><code>DOCUMENT_NODE</code></dfn> (9);
  2814 
  2815  <li><dfn id="dom-node-document_type_node" title="dom-Node-DOCUMENT_TYPE_NODE"><code>DOCUMENT_TYPE_NODE</code></dfn> (10);
  2816 
  2817  <li><dfn id="dom-node-document_fragment_node" title="dom-Node-DOCUMENT_FRAGMENT_NODE"><code>DOCUMENT_FRAGMENT_NODE</code></dfn> (11).
  2818 </ul>
  2819 
  2820 
  2821 <!-- NodeExodus
  2822 <hr>
  2823 
  2824 <p>The <dfn title=dom-Node-namespaceURI><code>namespaceURI</code></dfn> attribute must return the namespace that is associated with the node, if there is one and it's not the empty string, or null otherwise.
  2825 
  2826 <p>The <dfn title=dom-Node-prefix><code>prefix</code></dfn> attribute must return the prefix that is associated with the node, if there is one and it's not the empty string, or null otherwise.
  2827 <!- - support setting? - - On setting, it must run these steps:
  2828 
  2829 <ol>
  2830  <li><p>Let <var title>prefix</var> be the value being assigned.
  2831  <li>
  2832   <p>If <var title>prefix</var> is not null, run these substeps:
  2833   <ol>
  2834    <li><p>If <var title>prefix</var> does not match the
  2835    <code data-anolis-spec=xml>Name</code> production in XML,
  2836    <span title=concept-throw>throw</span> an
  2837    "<code>InvalidCharacterError</code>" exception and terminate these
  2838    steps.
  2839    <li><p>If <var title>prefix</var> does not match the <code
  2840    data-anolis-spec=xmlns>NCName</code> production in Namespaces in XML, <span title=concept-throw>throw</span> a
  2841    "<code>NamespaceError</code>" exception and
  2842    terminate these steps.
  2843   </ol>
  2844  <li><p>Actually this does not match any browser. Let's try to drop it instead.
  2845 </ol>- ->
  2846 
  2847 <p>The <dfn title=dom-Node-localName><code>localName</code></dfn> attribute
  2848 must return the local name that is associated with the node, if it has one,
  2849 and null otherwise.-->
  2850 
  2851 <p>The <dfn id="dom-node-nodename" title="dom-Node-nodeName"><code>nodeName</code></dfn> attribute
  2852 must return the following, depending on the <a href="#context-object">context object</a>:
  2853 
  2854 <dl class="switch">
  2855  <dt><code><a href="#element">Element</a></code>
  2856  <dd><p>Its <code title="dom-Element-tagName"><a href="#dom-element-tagname">tagName</a></code> attribute value.
  2857 
  2858  <!--AttrExodus
  2859  <dt><code>Attr</code>
  2860  <dd><p>The <span>context object</span>'s
  2861  <code title=dom-Attr-name>name</code> attribute.
  2862  -->
  2863 
  2864  <dt><code><a href="#text">Text</a></code>
  2865  <dd><p>"<code title="">#text</code>".
  2866 
  2867  <dt><code><a href="#processinginstruction">ProcessingInstruction</a></code>
  2868  <dd><p>Its <a href="#concept-pi-target" title="concept-PI-target">target</a>.
  2869 
  2870  <dt><code><a href="#comment">Comment</a></code>
  2871  <dd><p>"<code title="">#comment</code>".
  2872 
  2873  <dt><code><a href="#document">Document</a></code>
  2874  <dd><p>"<code title="">#document</code>".
  2875 
  2876  <dt><code><a href="#documenttype">DocumentType</a></code>
  2877  <dd><p>Its <a href="#concept-doctype-name" title="concept-doctype-name">name</a>.
  2878 
  2879  <dt><code><a href="#documentfragment">DocumentFragment</a></code>
  2880  <dd><p>"<code title="">#document-fragment</code>".
  2881 </dl>
  2882 
  2883 <hr>
  2884 
  2885 <dl class="domintro">
  2886  <dt><code><var title="">node</var> . <a href="#dom-node-baseuri" title="dom-Node-baseURI">baseURI</a></code>
  2887  <dd><p>Returns the <a href="#concept-node-base-url" title="concept-node-base-url">base URL</a>.
  2888 </dl>
  2889 
  2890 <p>The <dfn id="dom-node-baseuri" title="dom-Node-baseURI"><code>baseURI</code></dfn> attribute must return the associated <a href="#concept-node-base-url" title="concept-node-base-url">base URL</a>.
  2891 
  2892 <!--AttrExodus
  2893 <hr>
  2894 
  2895 <p>The <dfn title=dom-Node-hasAttributes><code>hasAttributes()</code></dfn>
  2896 method must return true if there are any attributes associated with the
  2897 <span>context object</span>, if it is an <code>Element</code> node, and false
  2898 otherwise.
  2899 
  2900 <p>The <dfn title=dom-Node-attributes><code>attributes</code></dfn> attribute must return a <code>NamedNodeMap</code> of all the <code>Attr</code> nodes associated with the node of the <span>context object</span>, if it is an <code>Element</code> node, or null otherwise.
  2901 -->
  2902 
  2903 <hr>
  2904 
  2905 <dl class="domintro">
  2906  <dt><code><var title="">node</var> . <a href="#dom-node-ownerdocument" title="dom-Node-ownerDocument">ownerDocument</a></code>
  2907  <dd>
  2908   <p>Returns the <a href="#concept-node-document" title="concept-node-document">node document</a>.
  2909   <p>Returns null for <a href="#concept-document" title="concept-document">documents</a>.
  2910 
  2911  <dt><code><var title="">node</var> . <a href="#dom-node-parentnode" title="dom-Node-parentNode">parentNode</a></code>
  2912  <dd><p>Returns the <a href="#concept-tree-parent" title="concept-tree-parent">parent</a>.
  2913 
  2914  <dt><code><var title="">node</var> . <a href="#dom-node-parentelement" title="dom-Node-parentElement">parentElement</a></code>
  2915  <dd><p>Returns the <a href="#parent-element">parent element</a>.
  2916 
  2917  <dt><code><var title="">node</var> . <a href="#dom-node-haschildnodes" title="dom-Node-hasChildNodes">hasChildNodes()</a></code>
  2918  <dd><p>Returns whether <var title="">node</var> has
  2919  <a href="#concept-tree-child" title="concept-tree-child">children</a>.
  2920 
  2921  <dt><code><var title="">node</var> . <a href="#dom-node-childnodes" title="dom-Node-childNodes">childNodes</a></code>
  2922  <dd><p>Returns the <a href="#concept-tree-child" title="concept-tree-child">children</a>.
  2923 
  2924  <dt><code><var title="">node</var> . <a href="#dom-node-firstchild" title="dom-Node-firstChild">firstChild</a></code>
  2925  <dd><p>Returns the <a href="#concept-tree-first-child" title="concept-tree-first-child">first child</a>.
  2926 
  2927  <dt><code><var title="">node</var> . <a href="#dom-node-lastchild" title="dom-Node-lastChild">lastChild</a></code>
  2928  <dd><p>Returns the <a href="#concept-tree-last-child" title="concept-tree-last-child">last child</a>.
  2929 
  2930  <dt><code><var title="">node</var> . <a href="#dom-node-previoussibling" title="dom-Node-previousSibling">previousSibling</a></code>
  2931  <dd><p>Returns the
  2932  <a href="#concept-tree-previous-sibling" title="concept-tree-previous-sibling">previous sibling</a>.
  2933 
  2934  <dt><code><var title="">node</var> . <a href="#dom-node-nextsibling" title="dom-Node-nextSibling">nextSibling</a></code>
  2935  <dd><p>Returns the
  2936  <a href="#concept-tree-next-sibling" title="concept-tree-next-sibling">next sibling</a>.
  2937 </dl>
  2938 
  2939 <div class="impl">
  2940 
  2941 <p>The <dfn id="dom-node-ownerdocument" title="dom-Node-ownerDocument"><code>ownerDocument</code></dfn>
  2942 attribute must run these steps:
  2943 <ol>
  2944  <li>If the <a href="#context-object">context object</a> is a
  2945  <a href="#concept-document" title="concept-document">document</a>, return null and terminate these
  2946  steps.
  2947 
  2948  <li>Return the <a href="#concept-node-document" title="concept-node-document">node document</a>.
  2949 </ol>
  2950 
  2951 <div class="note">
  2952 <p>The <a href="#concept-node-document" title="concept-node-document">node document</a> of a
  2953 <a href="#concept-document" title="concept-document">document</a> is that
  2954 <a href="#concept-document" title="concept-document">document</a> itself.
  2955 <p>All <a href="#concept-node" title="concept-node">nodes</a> have a
  2956 <a href="#concept-document" title="concept-document">document</a> at all times.
  2957 </div>
  2958 
  2959 <p>The <dfn id="dom-node-parentnode" title="dom-Node-parentNode"><code>parentNode</code></dfn>
  2960 attribute must return the <a href="#concept-tree-parent" title="concept-tree-parent">parent</a>.
  2961 <!-- AttrExodus
  2962 <li><p>If the <span>context object</span> is an <code>Attr</code> node,
  2963 return null and terminate these steps.
  2964 -->
  2965 
  2966 <p>The <dfn id="dom-node-parentelement" title="dom-Node-parentElement"><code>parentElement</code></dfn>
  2967 attribute must return the <a href="#parent-element">parent element</a>.
  2968 
  2969 <p>The <dfn id="dom-node-haschildnodes" title="dom-Node-hasChildNodes"><code>hasChildNodes()</code></dfn>
  2970 method must return true if the <a href="#context-object">context object</a> has
  2971 <a href="#concept-tree-child" title="concept-tree-child">children</a>, or false otherwise.
  2972 
  2973 <p>The <dfn id="dom-node-childnodes" title="dom-Node-childNodes"><code>childNodes</code></dfn>
  2974 attribute must return a <code><a href="#nodelist">NodeList</a></code> rooted at the
  2975 <a href="#context-object">context object</a> matching only
  2976 <a href="#concept-tree-child" title="concept-tree-child">children</a>.
  2977 
  2978 <p>The <dfn id="dom-node-firstchild" title="dom-Node-firstChild"><code>firstChild</code></dfn>
  2979 attribute must return the
  2980 <a href="#concept-tree-first-child" title="concept-tree-first-child">first child</a>.
  2981 
  2982 <p>The <dfn id="dom-node-lastchild" title="dom-Node-lastChild"><code>lastChild</code></dfn> attribute must return the <a href="#concept-tree-last-child" title="concept-tree-last-child">last child</a>.
  2983 
  2984 <p>The
  2985 <dfn id="dom-node-previoussibling" title="dom-Node-previousSibling"><code>previousSibling</code></dfn>
  2986 attribute must return the
  2987 <a href="#concept-tree-previous-sibling" title="concept-tree-previous-sibling">previous sibling</a>.
  2988 <!-- AttrExodus
  2989  <li><p>If the <span>context object</span> is an <code>Attr</code> node,
  2990  return null and terminate these steps.
  2991 -->
  2992 
  2993 <p>The <dfn id="dom-node-nextsibling" title="dom-Node-nextSibling"><code>nextSibling</code></dfn>
  2994 attribute must return the
  2995 <a href="#concept-tree-next-sibling" title="concept-tree-next-sibling">next sibling</a>.
  2996 <!-- AttrExodus
  2997  <li><p>If the <span>context object</span> is an <code>Attr</code> node,
  2998  return null and terminate these steps.
  2999 -->
  3000 
  3001 </div>
  3002 
  3003 <hr>
  3004 
  3005 <!-- TODO: domintro -->
  3006 
  3007 <p>The <dfn id="dom-node-nodevalue" title="dom-Node-nodeValue"><code>nodeValue</code></dfn> attribute
  3008 must return the following, depending on the <a href="#context-object">context object</a>:
  3009 
  3010 <dl class="switch">
  3011  <!--AttrExodus <dt><code>Attr</code> -->
  3012  <dt><code><a href="#text">Text</a></code>
  3013  <dt><code><a href="#comment">Comment</a></code>
  3014  <dt><code><a href="#processinginstruction">ProcessingInstruction</a></code>
  3015  <dd><p>The <a href="#context-object">context object</a>'s
  3016  <a href="#concept-cd-data" title="concept-CD-data">data</a>.
  3017 
  3018  <dt>Any other node
  3019  <dd><p>Null.
  3020 </dl>
  3021 
  3022 <p>Setting the <code title="dom-Node-nodeValue"><a href="#dom-node-nodevalue">nodeValue</a></code> attribute
  3023 must do as described below, depending on the <a href="#context-object">context object</a>:
  3024 
  3025 <dl class="switch">
  3026  <!--AttrExodus <dt><code>Attr</code> -->
  3027  <dt><code><a href="#text">Text</a></code>
  3028  <dt><code><a href="#comment">Comment</a></code>
  3029  <dt><code><a href="#processinginstruction">ProcessingInstruction</a></code>
  3030  <dd><p><a href="#concept-cd-replace" title="concept-CD-replace">Replace data</a> with node
  3031  <a href="#context-object">context object</a>, offset 0, count
  3032  <code title="dom-CharacterData-length"><a href="#dom-characterdata-length">length</a></code> attribute value, and
  3033  data new value.
  3034 
  3035  <dt>Any other node
  3036  <dd><p>Do nothing.
  3037 </dl>
  3038 
  3039 <p>The <dfn id="dom-node-textcontent" title="dom-Node-textContent"><code>textContent</code></dfn>
  3040 attribute must return the following, depending on the
  3041 <a href="#context-object">context object</a>:
  3042 
  3043 <dl class="switch">
  3044  <dt><code><a href="#documentfragment">DocumentFragment</a></code>
  3045  <dt><code><a href="#element">Element</a></code>
  3046  <!--AttrExodus <dt><code>Attr</code> -->
  3047  <dd><p>The concatenation of <a href="#concept-cd-data" title="concept-CD-data">data</a> of all
  3048  the <code><a href="#text">Text</a></code> <a href="#concept-node" title="concept-node">node</a>
  3049  <a href="#concept-tree-descendant" title="concept-tree-descendant">descendants</a> of the
  3050  <a href="#context-object">context object</a>, in
  3051  <a href="#concept-tree-order" title="concept-tree-order">tree order</a>.
  3052 
  3053  <dt><code><a href="#text">Text</a></code>
  3054  <dt><code><a href="#processinginstruction">ProcessingInstruction</a></code>
  3055  <dt><code><a href="#comment">Comment</a></code>
  3056  <dd><p>The <a href="#context-object">context object</a>'s
  3057  <a href="#concept-cd-data" title="concept-CD-data">data</a>.
  3058 
  3059  <dt>Any other node
  3060  <dd><p>Null.
  3061 </dl>
  3062 
  3063 <p>The <code title="dom-Node-textContent"><a href="#dom-node-textcontent">textContent</a></code> attribute must,
  3064 on setting, if the new value is null, act as if it was the empty string
  3065 instead, and then do as described below, depending on the <a href="#context-object">context object</a>:
  3066 
  3067 <dl class="switch">
  3068  <dt><code><a href="#documentfragment">DocumentFragment</a></code>
  3069  <dt><code><a href="#element">Element</a></code>
  3070  <!--AttrExodus <dt><code>Attr</code> -->
  3071  <dd>
  3072   <ol>
  3073    <li><p>Let <var title="">node</var> be null.
  3074 
  3075    <li><p>If new value is not the empty string, set <var title="">node</var> to
  3076    a new <code><a href="#text">Text</a></code> <a href="#concept-node" title="concept-node">node</a> whose
  3077    <a href="#concept-cd-data" title="concept-CD-data">data</a> is new value.
  3078 
  3079    <li><p><a href="#concept-node-replace-all" title="concept-node-replace-all">Replace all</a> with
  3080    <var title="">node</var> within the <a href="#context-object">context object</a>.
  3081   </ol>
  3082 
  3083  <dt><code><a href="#text">Text</a></code>
  3084  <dt><code><a href="#processinginstruction">ProcessingInstruction</a></code>
  3085  <dt><code><a href="#comment">Comment</a></code>
  3086  <dd><p><a href="#concept-cd-replace" title="concept-CD-replace">Replace data</a> with node
  3087  <a href="#context-object">context object</a>, offset 0, count
  3088  <code title="dom-CharacterData-length"><a href="#dom-characterdata-length">length</a></code> attribute value, and
  3089  data new value.
  3090 
  3091  <dt>Any other node
  3092  <dd><p>Do nothing.
  3093 </dl>
  3094 
  3095 <hr>
  3096 
  3097 <dl class="domintro">
  3098  <dt><code><var title="">node</var> . <a href="#dom-node-normalize" title="dom-Node-normalize">normalize</a>()</code>
  3099  <dd><p>Removes <a href="#concept-node-empty" title="concept-node-empty">empty</a>
  3100  <code><a href="#text">Text</a></code> <a href="#concept-node" title="concept-node">nodes</a> and concatenates
  3101  the <a href="#concept-cd-data" title="concept-CD-data">data</a> of remaining
  3102  <a href="#contiguous-text-nodes">contiguous <code>Text</code> nodes</a> into the first of their
  3103  <a href="#concept-node" title="concept-node">nodes</a>.
  3104 </dl>
  3105 
  3106 <p>The <dfn id="dom-node-normalize" title="dom-Node-normalize"><code>normalize()</code></dfn> method
  3107 must run these steps:</p>
  3108 
  3109 <p>For each <code><a href="#text">Text</a></code> <a href="#concept-node" title="concept-node">node</a>
  3110 <a href="#concept-tree-descendant" title="concept-tree-descendant">descendant</a> of the
  3111 <a href="#context-object">context object</a>:
  3112 
  3113 <ol>
  3114  <li><p>Let <var title="">node</var> be the <code><a href="#text">Text</a></code>
  3115  <a href="#concept-node" title="concept-node">node</a>
  3116  <a href="#concept-tree-descendant" title="concept-tree-descendant">descendant</a>.
  3117 
  3118  <li><p>Let <var title="">length</var> be <var title="">node</var>'s
  3119  <code title="dom-CharacterData-length"><a href="#dom-characterdata-length">length</a></code> attribute value.
  3120 
  3121  <li><p>If <var title="">length</var> is zero,
  3122  <a href="#concept-node-remove" title="concept-node-remove">remove</a> <var title="">node</var> and
  3123  continue with the next <code><a href="#text">Text</a></code>
  3124  <a href="#concept-node" title="concept-node">node</a>, if any.
  3125 
  3126  <li><p>Let <var title="">data</var> be the concatenation of the
  3127  <a href="#concept-cd-data" title="concept-CD-data">data</a> of <var title="">node</var>'s
  3128  <a href="#contiguous-text-nodes">contiguous <code>Text</code> nodes</a> (excluding itself), in
  3129  <a href="#concept-tree-order" title="concept-tree-order">tree order</a>.
  3130 
  3131  <li><p><a href="#concept-cd-replace" title="concept-CD-replace">Replace data</a> with node
  3132  <var title="">node</var>, offset <var title="">length</var>,
  3133  count 0, and data <var title="">data</var>.
  3134 
  3135  <li><p>Let <var title="">current node</var> be <var title="">node</var>'s
  3136  <a href="#concept-tree-next-sibling" title="concept-tree-next-sibling">next sibling</a>.
  3137 
  3138  <li><p>While <var title="">current node</var> is a <code><a href="#text">Text</a></code> node:
  3139 
  3140  <ol>
  3141   <li><p>For each <a href="#concept-range" title="concept-range">range</a> whose
  3142   <a href="#concept-range-start-node" title="concept-range-start-node">start node</a> is
  3143   <var title="">current node</var>, add <var title="">length</var> to its
  3144   <a href="#concept-range-start-offset" title="concept-range-start-offset">start offset</a> and set its
  3145   <a href="#concept-range-start-node" title="concept-range-start-node">start node</a> to
  3146   <var title="">node</var>.
  3147 
  3148   <li><p>For each <a href="#concept-range" title="concept-range">range</a> whose
  3149   <a href="#concept-range-end-node" title="concept-range-end-node">end node</a> is
  3150   <var title="">current node</var>, add <var title="">length</var> to its
  3151   <a href="#concept-range-end-offset" title="concept-range-end-offset">end offset</a> and set its
  3152   <a href="#concept-range-end-node" title="concept-range-end-node">end node</a> to
  3153   <var title="">node</var>.
  3154 
  3155   <li><p>For each <a href="#concept-range" title="concept-range">range</a> whose
  3156   <a href="#concept-range-start-node" title="concept-range-start-node">start node</a> is
  3157   <var title="">current node</var>'s
  3158   <a href="#concept-tree-parent" title="concept-tree-parent">parent</a> and
  3159   <a href="#concept-range-start-offset" title="concept-range-start-offset">start offset</a> is
  3160   <var title="">current node</var>'s
  3161   <a href="#concept-tree-index" title="concept-tree-index">index</a>, set its
  3162   <a href="#concept-range-start-node" title="concept-range-start-node">start node</a> to
  3163   <var title="">node</var> and its
  3164   <a href="#concept-range-start-offset" title="concept-range-start-offset">start offset</a> to
  3165   <var title="">length</var>.
  3166 
  3167   <li><p>For each <a href="#concept-range" title="concept-range">range</a> whose
  3168   <a href="#concept-range-end-node" title="concept-range-end-node">end node</a> is
  3169   <var title="">current node</var>'s
  3170   <a href="#concept-tree-parent" title="concept-tree-parent">parent</a> and
  3171   <a href="#concept-range-end-offset" title="concept-range-end-offset">end offset</a> is
  3172   <var title="">current node</var>'s
  3173   <a href="#concept-tree-index" title="concept-tree-index">index</a>, set its
  3174   <a href="#concept-range-end-node" title="concept-range-end-node">end node</a> to
  3175   <var title="">node</var> and its
  3176   <a href="#concept-range-end-offset" title="concept-range-end-offset">end offset</a> to
  3177   <var title="">length</var>.
  3178 
  3179   <li><p>Add <var title="">current node</var>'s
  3180   <code title="dom-CharacterData-length"><a href="#dom-characterdata-length">length</a></code> attribute value to
  3181   <var title="">length</var>.
  3182 
  3183   <li><p>Set <var title="">current node</var> to its
  3184   <a href="#concept-tree-next-sibling" title="concept-tree-next-sibling">next sibling</a>.
  3185  </ol>
  3186 
  3187  <li><p><a href="#concept-node-remove" title="concept-node-remove">Remove</a>
  3188  <var title="">node</var>'s
  3189  <a href="#contiguous-text-nodes">contiguous <code>Text</code> nodes</a> (excluding itself), in
  3190  <a href="#concept-tree-order" title="concept-tree-order">tree order</a>.
  3191 </ol>
  3192 
  3193 <hr>
  3194 
  3195 <dl class="domintro">
  3196  <dt><code><var title="">node</var> . <a href="#dom-node-clonenode" title="dom-Node-cloneNode">cloneNode</a>([<var title="">deep</var>])</code>
  3197  <dd><p>Returns a copy of <var title="">node</var>. If
  3198  <var title="">deep</var> is true or omitted, the copy also includes the
  3199  <var title="">node</var> <a href="#concept-tree-child" title="concept-tree-child">children</a>.
  3200 
  3201  <dt><code><var title="">node</var> . <a href="#dom-node-isequalnode" title="dom-Node-isEqualNode">isEqualNode</a>(<var title="">other</var>)</code>
  3202  <dd><p>Returns whether <var title="">node</var> and <var title="">other</var>
  3203  have the same properties.
  3204 </dl>
  3205 
  3206 <div class="impl">
  3207 
  3208 <p>Specifications may define
  3209 <dfn id="concept-node-clone-ext" title="concept-node-clone-ext">cloning steps</dfn> for all or some
  3210 <a href="#concept-node" title="concept-node">nodes</a>.
  3211 
  3212 <p class="note">HTML defines
  3213 <a href="#concept-node-clone-ext" title="concept-node-clone-ext">cloning steps</a> for
  3214 <code class="external" data-anolis-spec="html"><a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/scripting-1.html#the-script-element">script</a></code> and
  3215 <code class="external" data-anolis-spec="html"><a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/the-input-element.html#the-input-element">input</a></code> elements. SVG ought to do the same
  3216 for its <code title="">script</code> elements, but does not call this out at
  3217 the moment.
  3218 
  3219 <p>To <dfn id="concept-node-clone" title="concept-node-clone">clone</dfn> a <var title="">node</var>,
  3220 optionally with a <i title="">document</i> <var title="">ownerDocument</var> and a
  3221 <i title="">clone children flag</i>, run these steps:
  3222 <!-- This algorithm is used by dom-Node-cloneNode, dom-Document-importNode,
  3223 dom-Range-extractContents, dom-Range-cloneContents -->
  3224 
  3225 <ol>
  3226  <li><p>If <i title="">document</i> is not given let
  3227  <var title="">ownerDocument</var> be <var title="">node</var>'s
  3228  <a href="#concept-node-document" title="concept-node-document">node document</a>.
  3229  <li><p>Let <var title="">copy</var> be a <a href="#concept-node" title="concept-node">node</a>
  3230  that implements the same interfaces as <var title="">node</var>.
  3231  <li>
  3232   <p>If <var title="">copy</var> is a
  3233   <a href="#concept-document" title="concept-document">document</a> set its
  3234   <a href="#concept-node-document" title="concept-node-document">node document</a> and
  3235   <var title="">ownerDocument</var> to <var title="">copy</var>.
  3236   <p>Otherwise, set <var title="">copy</var>'s
  3237   <a href="#concept-node-document" title="concept-node-document">node document</a> to
  3238   <var title="">ownerDocument</var>.
  3239  <li>
  3240   <p>Copy the following, depending on the type of <var title="">node</var>:
  3241   <dl class="switch">
  3242    <dt><code><a href="#element">Element</a></code>
  3243    <dd><p>Its <a href="#concept-element-namespace" title="concept-element-namespace">namespace</a>,
  3244    <a href="#concept-element-namespace-prefix" title="concept-element-namespace-prefix">namespace prefix</a>,
  3245    <a href="#concept-element-local-name" title="concept-element-local-name">local name</a>, and its
  3246    <a href="#concept-element-attribute" title="concept-element-attribute">attribute list</a>.
  3247 
  3248    <!--AttrExodus
  3249    <dt><code>Attr</code>
  3250    <dd><p><code title=dom-Attr-value>value</code>
  3251    -->
  3252 
  3253    <dt><code><a href="#documenttype">DocumentType</a></code>
  3254    <dd><p>Its <a href="#concept-doctype-name" title="concept-doctype-name">name</a>,
  3255    <a href="#concept-doctype-publicid" title="concept-doctype-publicid">public ID</a>, and
  3256    <a href="#concept-doctype-systemid" title="concept-doctype-systemid">system ID</a>.
  3257 
  3258    <dt><code><a href="#processinginstruction">ProcessingInstruction</a></code>
  3259    <dd><p>Its <a href="#concept-pi-target" title="concept-PI-target">target</a> and
  3260    <a href="#concept-cd-data" title="concept-CD-data">data</a>.
  3261 
  3262    <dt><code><a href="#text">Text</a></code>
  3263    <dt><code><a href="#comment">Comment</a></code>
  3264    <dd><p>Its <a href="#concept-cd-data" title="concept-CD-data">data</a>.
  3265 
  3266    <dt>Any other node
  3267    <dd><p>—
  3268   </dl>
  3269 
  3270  <li><p>Run any <a href="#concept-node-clone-ext" title="concept-node-clone-ext">cloning steps</a>
  3271  defined for <var title="">node</var> in
  3272  <a href="#other-applicable-specifications">other applicable specifications</a>.
  3273 
  3274  <li><p>If the <i title="">clone children flag</i> is set,
  3275  <a href="#concept-node-clone" title="concept-node-clone">clone</a> all the
  3276  <a href="#concept-tree-child" title="concept-tree-child">children</a> of <var title="">node</var> and
  3277  append them to <var title="">copy</var>, with <var title="">ownerDocument</var>
  3278  as specified and the <i title="">clone children flag</i> being set.
  3279 
  3280  <li><p>Return <var title="">copy</var>.
  3281 </ol>
  3282 
  3283 <p>The
  3284 <dfn id="dom-node-clonenode" title="dom-Node-cloneNode"><code>cloneNode(<var title="">deep</var>)</code></dfn>
  3285 method must return a <a href="#concept-node-clone" title="concept-node-clone">clone</a> of the
  3286 <a href="#context-object">context object</a>, with the <i title="">clone children flag</i> set
  3287 if <var title="">deep</var> is true.
  3288 
  3289 <p>The
  3290 <dfn id="dom-node-isequalnode" title="dom-Node-isEqualNode"><code>isEqualNode(<var title="">node</var>)</code></dfn>
  3291 method must return true if all of the following conditions are true, and
  3292 false otherwise:
  3293 
  3294 <ul>
  3295  <li><p><var title="">node</var> is not null.
  3296  <li><p><var title="">node</var>'s
  3297  <code title="dom-Node-nodeType"><a href="#dom-node-nodetype">nodeType</a></code> attribute value is the same
  3298  as the <a href="#context-object">context object</a>'s
  3299  <code title="dom-Node-nodeType"><a href="#dom-node-nodetype">nodeType</a></code> attribute value.
  3300  <li>
  3301   <p>The following are also equal, depending on <var title="">node</var>:
  3302   <dl class="switch">
  3303    <dt><code><a href="#documenttype">DocumentType</a></code>
  3304    <dd><p>Its <a href="#concept-doctype-name" title="concept-doctype-name">name</a>,
  3305    <a href="#concept-doctype-publicid" title="concept-doctype-publicid">public ID</a>, and
  3306    <a href="#concept-doctype-systemid" title="concept-doctype-systemid">system ID</a>.
  3307 
  3308    <dt><code><a href="#element">Element</a></code>
  3309    <dd>
  3310     <p>Its <a href="#concept-element-namespace" title="concept-element-namespace">namespace</a>,
  3311     <a href="#concept-element-namespace-prefix" title="concept-element-namespace-prefix">namespace prefix</a>,
  3312     <a href="#concept-element-local-name" title="concept-element-local-name">local name</a>, and its
  3313     number of <a href="#concept-attribute" title="concept-attribute">attributes</a> in its
  3314     <a href="#concept-element-attribute" title="concept-element-attribute">attribute list</a>.
  3315 
  3316    <!--AttrExodus
  3317    <dt><code>Attr</code>
  3318    <dd><p><code title=dom-Attr-value>value</code>
  3319    -->
  3320 
  3321    <dt><code><a href="#processinginstruction">ProcessingInstruction</a></code>
  3322    <dd><p>Its <a href="#concept-pi-target" title="concept-PI-target">target</a> and
  3323    <a href="#concept-cd-data" title="concept-CD-data">data</a>.
  3324 
  3325    <dt><code><a href="#text">Text</a></code>
  3326    <dt><code><a href="#comment">Comment</a></code>
  3327    <dd><p>Its <a href="#concept-cd-data" title="concept-CD-data">data</a>.
  3328 
  3329    <dt>Any other node
  3330    <dd><p>—
  3331   </dl>
  3332  <li><p>If <var title="">node</var> is an <code><a href="#element">Element</a></code>, each
  3333  <a href="#concept-attribute" title="concept-attribute">attribute</a> in its
  3334  <a href="#concept-element-attribute" title="concept-element-attribute">attribute list</a> has an
  3335  <a href="#concept-attribute" title="concept-attribute">attribute</a> with the same
  3336  <a href="#concept-attribute-namespace" title="concept-attribute-namespace">namespace</a>,
  3337  <a href="#concept-attribute-local-name" title="concept-attribute-local-name">local name</a>, and
  3338  <a href="#concept-attribute-value" title="concept-attribute-value">value</a> in the
  3339  <a href="#context-object">context object</a>'s
  3340  <a href="#concept-element-attribute" title="concept-element-attribute">attribute list</a>.
  3341  <li><p><var title="">node</var> has the same number of
  3342  <a href="#concept-tree-child" title="concept-tree-child">children</a> as the
  3343  <a href="#context-object">context object</a>.
  3344  <li><p>Calling <code title="dom-Node-isEqualNode"><a href="#dom-node-isequalnode">isEqualNode()</a></code> on
  3345  each <a href="#concept-tree-child" title="concept-tree-child">child</a> of the
  3346  <a href="#context-object">context object</a>, with the
  3347  <a href="#concept-tree-child" title="concept-tree-child">child</a> of the same index in
  3348  <var title="">node</var> as argument returns true for every
  3349  <a href="#concept-tree-child" title="concept-tree-child">child</a>.
  3350 </ul>
  3351 
  3352 </div>
  3353 
  3354 <hr>
  3355 
  3356 <dl class="domintro">
  3357  <dt><code><var title="">node</var> . <a href="#dom-node-comparedocumentposition" title="dom-Node-compareDocumentPosition">compareDocumentPosition</a>(<var title="">other</var>)</code>
  3358  <dd>
  3359   <p>Returns a bitmask indicating the position of <var title="">other</var>
  3360   relative to <var title="">node</var>. These are the bits that can be set:
  3361 
  3362   <dl>
  3363    <dt><code><a href="#node">Node</a> . <a href="#dom-node-document_position_disconnected" title="dom-Node-DOCUMENT_POSITION_DISCONNECTED">DOCUMENT_POSITION_DISCONNECTED</a></code> (1)
  3364    <dd>Set when <var title="">node</var> and <var>other</var> are not in the
  3365    same <a href="#concept-document" title="concept-document">document</a>.
  3366 
  3367    <dt><code><a href="#node">Node</a> . <a href="#dom-node-document_position_preceding" title="dom-Node-DOCUMENT_POSITION_PRECEDING">DOCUMENT_POSITION_PRECEDING</a></code> (2)
  3368    <dd>Set when <var title="">other</var> is
  3369    <a href="#concept-tree-preceding" title="concept-tree-preceding">preceding</a>
  3370    <var title="">node</var>.
  3371 
  3372    <dt><code><a href="#node">Node</a> . <a href="#dom-node-document_position_following" title="dom-Node-DOCUMENT_POSITION_FOLLOWING">DOCUMENT_POSITION_FOLLOWING</a></code> (4)
  3373    <dd>Set when <var title="">other</var> is
  3374    <a href="#concept-tree-following" title="concept-tree-following">following</a>
  3375    <var title="">node</var>.
  3376 
  3377    <dt><code><a href="#node">Node</a> . <a href="#dom-node-document_position_contains" title="dom-Node-DOCUMENT_POSITION_CONTAINS">DOCUMENT_POSITION_CONTAINS</a></code> (8)
  3378    <dd>Set when <var title="">other</var> is an
  3379    <a href="#concept-tree-ancestor" title="concept-tree-ancestor">ancestor</a> of
  3380    <var title="">node</var>.
  3381 
  3382    <dt><code><a href="#node">Node</a> . <a href="#dom-node-document_position_contained_by" title="dom-Node-DOCUMENT_POSITION_CONTAINED_BY">DOCUMENT_POSITION_CONTAINED_BY</a></code> (16, 10 in hexadecimal)
  3383    <dd>Set when <var title="">other</var> is a
  3384    <a href="#concept-tree-descendant" title="concept-tree-descendant">descendant</a> of
  3385    <var title="">node</var>.
  3386   </dl>
  3387 
  3388  <dt><code><var title="">node</var> . <a href="#dom-node-contains" title="dom-Node-contains">contains</a>(<var title="">other</var>)</code>
  3389  <dd><p>Returns true if <var title="">other</var> is an
  3390  <a href="#concept-tree-inclusive-descendant" title="concept-tree-inclusive-descendant">inclusive descendant</a>
  3391  of <var title="">node</var>, or false otherwise.
  3392 </dl>
  3393 
  3394 <p>These are the constants
  3395 <code title="dom-Node-compareDocumentPosition"><a href="#dom-node-comparedocumentposition">compareDocumentPosition()</a></code>
  3396 returns as mask:
  3397 
  3398 <ul class="brief">
  3399  <li><dfn id="dom-node-document_position_disconnected" title="dom-Node-DOCUMENT_POSITION_DISCONNECTED"><code>DOCUMENT_POSITION_DISCONNECTED</code></dfn> (1);
  3400  <li><dfn id="dom-node-document_position_preceding" title="dom-Node-DOCUMENT_POSITION_PRECEDING"><code>DOCUMENT_POSITION_PRECEDING</code></dfn> (2);
  3401  <li><dfn id="dom-node-document_position_following" title="dom-Node-DOCUMENT_POSITION_FOLLOWING"><code>DOCUMENT_POSITION_FOLLOWING</code></dfn> (4);
  3402  <li><dfn id="dom-node-document_position_contains" title="dom-Node-DOCUMENT_POSITION_CONTAINS"><code>DOCUMENT_POSITION_CONTAINS</code></dfn> (8);
  3403  <li><dfn id="dom-node-document_position_contained_by" title="dom-Node-DOCUMENT_POSITION_CONTAINED_BY"><code>DOCUMENT_POSITION_CONTAINED_BY</code></dfn> (16, 10 in hexadecimal);
  3404  <li><dfn id="dom-node-document_position_implementation_specific" title="dom-Node-DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC"><code>DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC</code> (32, 20 in hexadecimal).
  3405 </dfn></ul>
  3406 
  3407 <p>The <dfn id="dom-node-comparedocumentposition" title="dom-Node-compareDocumentPosition"><code>compareDocumentPosition(<var>other</var>)</code></dfn>
  3408 method must run these steps:
  3409 
  3410 <ol>
  3411  <li><p>Let <var title="">reference</var> be the <a href="#context-object">context object</a>.
  3412  <li><p>If <var title="">other</var> and <var title="">reference</var> are the
  3413  same object, return zero and terminate these steps.
  3414 
  3415  <li>
  3416   <p>If <var title="">other</var> and <var title="">reference</var> are not
  3417   in the same <a href="#concept-tree" title="concept-tree">tree</a>, return the result of
  3418   adding
  3419   <code title="dom-Node-DOCUMENT_POSITION_DISCONNECTED"><a href="#dom-node-document_position_disconnected">DOCUMENT_POSITION_DISCONNECTED</a></code>,
  3420   <code title="dom-Node-DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC"><a href="#dom-node-document_position_implementation_specific">DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC</a></code>,
  3421   and either
  3422   <code title="dom-Node-DOCUMENT_POSITION_PRECEDING"><a href="#dom-node-document_position_preceding">DOCUMENT_POSITION_PRECEDING</a></code> or
  3423   <code title="dom-Node-DOCUMENT_POSITION_FOLLOWING"><a href="#dom-node-document_position_following">DOCUMENT_POSITION_FOLLOWING</a></code>,
  3424   with the constraint that this is to be consistent, together and terminate
  3425   these steps.
  3426 
  3427   <p class="note">Whether to return
  3428   <code title="dom-Node-DOCUMENT_POSITION_PRECEDING"><a href="#dom-node-document_position_preceding">DOCUMENT_POSITION_PRECEDING</a></code> or
  3429   <code title="dom-Node-DOCUMENT_POSITION_FOLLOWING"><a href="#dom-node-document_position_following">DOCUMENT_POSITION_FOLLOWING</a></code>
  3430   is typically implemented via pointer comparison. In JavaScript
  3431   implementations <code title="">Math.random()</code> can be used.
  3432 
  3433  <li><p>If <var title="">other</var> is an
  3434  <a href="#concept-tree-ancestor" title="concept-tree-ancestor">ancestor</a> of
  3435  <var title="">reference</var>, return the result of adding
  3436  <code title="dom-Node-DOCUMENT_POSITION_CONTAINS"><a href="#dom-node-document_position_contains">DOCUMENT_POSITION_CONTAINS</a></code>
  3437  to
  3438  <code title="dom-Node-DOCUMENT_POSITION_PRECEDING"><a href="#dom-node-document_position_preceding">DOCUMENT_POSITION_PRECEDING</a></code>
  3439  and terminate these steps.
  3440 
  3441  <li><p>If <var title="">other</var> is a
  3442  <a href="#concept-tree-descendant" title="concept-tree-descendant">descendant</a> of
  3443  <var title="">reference</var>, return the result of adding
  3444  <code title="dom-Node-DOCUMENT_POSITION_CONTAINED_BY"><a href="#dom-node-document_position_contained_by">DOCUMENT_POSITION_CONTAINED_BY</a></code>
  3445  to
  3446  <code title="dom-Node-DOCUMENT_POSITION_FOLLOWING"><a href="#dom-node-document_position_following">DOCUMENT_POSITION_FOLLOWING</a></code>
  3447  and terminate these steps.
  3448 
  3449  <li><p>If <var title="">other</var> is
  3450  <a href="#concept-tree-preceding" title="concept-tree-preceding">preceding</a>
  3451  <var title="">reference</var> return
  3452  <code title="dom-Node-DOCUMENT_POSITION_PRECEDING"><a href="#dom-node-document_position_preceding">DOCUMENT_POSITION_PRECEDING</a></code>
  3453  and terminate these steps.
  3454 
  3455  <li><p>Return
  3456  <code title="dom-Node-DOCUMENT_POSITION_FOLLOWING"><a href="#dom-node-document_position_following">DOCUMENT_POSITION_FOLLOWING</a></code>.
  3457 </ol>
  3458 
  3459 <!-- AttrExodus compareDocumentPosition() works differently if Attr inherits
  3460      from Node -->
  3461 
  3462 <p>The
  3463 <dfn id="dom-node-contains" title="dom-Node-contains"><code>contains(<var title="">other</var>)</code></dfn>
  3464 method must return true if <var title="">other</var> is an
  3465 <a href="#concept-tree-inclusive-descendant" title="concept-tree-inclusive-descendant">inclusive descendant</a> of
  3466 the <a href="#context-object">context object</a>, or false otherwise (including when
  3467 <var title="">other</var> is null).
  3468 
  3469 <hr>
  3470 
  3471 <!-- TODO: domintro -->
  3472 
  3473 <!--
  3474  XXX apparently these algorithms might not be quite correct
  3475  https://bugzilla.mozilla.org/show_bug.cgi?id=312019
  3476  https://bugzilla.mozilla.org/show_bug.cgi?id=505178
  3477 -->
  3478 
  3479 <p>To <dfn id="locate-a-namespace-prefix">locate a namespace prefix</dfn> for an <var title="">element</var> using
  3480 <var title="">namespace</var> run these steps:
  3481 
  3482 <ol>
  3483  <li><p>If <var title="">element</var>'s
  3484  <a href="#concept-element-namespace" title="concept-element-namespace">namespace</a> is
  3485  <var title="">namespace</var> and its
  3486  <a href="#concept-element-namespace-prefix" title="concept-element-namespace-prefix">namespace prefix</a> is not
  3487  null return its
  3488  <a href="#concept-element-namespace-prefix" title="concept-element-namespace-prefix">namespace prefix</a> and
  3489  terminate these steps.
  3490 
  3491  <li><p>If, <var title="">element</var>
  3492  <a href="#concept-element-attribute-has" title="concept-element-attribute-has">has</a> an
  3493  <a href="#concept-attribute" title="concept-attribute">attribute</a> whose
  3494  <a href="#concept-attribute-namespace-prefix" title="concept-attribute-namespace-prefix">namespace prefix</a> is
  3495  "<code title="">xmlns</code>" and
  3496  <a href="#concept-attribute-value" title="concept-attribute-value">value</a> is
  3497  <var title="">namespace</var>, then return <var title="">element</var>'s first
  3498  such <a href="#concept-attribute" title="concept-attribute">attribute</a>'s
  3499  <a href="#concept-attribute-local-name" title="concept-attribute-local-name">local name</a>
  3500  and terminate these steps.
  3501 
  3502  <li><p>If <var title="">element</var>'s <a href="#parent-element">parent element</a> is not null,
  3503  return the result of running <a href="#locate-a-namespace-prefix">locate a namespace prefix</a> on that
  3504  <a href="#concept-element" title="concept-element">element</a> using <var title="">namespace</var>.
  3505  Otherwise, return null.
  3506 </ol>
  3507 
  3508 <p>To <dfn id="locate-a-namespace">locate a namespace</dfn> for a <var title="">node</var> using
  3509 <var title="">prefix</var> depends on the <var title="">node</var>:
  3510 
  3511 <dl class="switch">
  3512  <dt><code><a href="#element">Element</a></code>
  3513  <dd>
  3514   <ol>
  3515    <li><p>If its <a href="#concept-element-namespace" title="concept-element-namespace">namespace</a> is
  3516    not null and its
  3517    <a href="#concept-element-namespace-prefix" title="concept-element-namespace-prefix">namespace prefix</a> is
  3518    <var title="">prefix</var> return
  3519    <a href="#concept-element-namespace" title="concept-element-namespace">namespace</a> and terminate
  3520    these steps.
  3521 
  3522    <li>
  3523     <p>If it <a href="#concept-element-attribute-has" title="concept-element-attribute-has">has</a> an
  3524     <a href="#concept-attribute" title="concept-attribute">attribute</a> whose
  3525     <a href="#concept-attribute-namespace" title="concept-attribute-namespace">namespace</a> is the
  3526     <a href="#xmlns-namespace">XMLNS namespace</a>,
  3527     <a href="#concept-attribute-namespace-prefix" title="concept-attribute-namespace-prefix">namespace prefix</a>
  3528     is "<code title="">xmlns</code>" and
  3529     <a href="#concept-attribute-local-name" title="concept-attribute-local-name">local name</a> is
  3530     <var title="">prefix</var>, or if <var title="">prefix</var> is null and it
  3531     <a href="#concept-element-attribute-has" title="concept-element-attribute-has">has</a> an
  3532     <a href="#concept-attribute" title="concept-attribute">attribute</a> whose
  3533     <a href="#concept-attribute-namespace" title="concept-attribute-namespace">namespace</a> is the
  3534     <a href="#xmlns-namespace">XMLNS namespace</a>,
  3535     <a href="#concept-attribute-namespace-prefix" title="concept-attribute-namespace-prefix">namespace prefix</a>
  3536     is null and <a href="#concept-attribute-local-name" title="concept-attribute-local-name">local name</a>
  3537     is "<code title="">xmlns</code>":
  3538 
  3539     <ol>
  3540      <li><p>Let <var title="">value</var> be its
  3541      <a href="#concept-attribute-value" title="concept-attribute-value">value</a> if it is not the empty
  3542      string, or null otherwise.
  3543 
  3544      <li><p>Return <var title="">value</var> and terminate these steps.
  3545     </ol>
  3546 
  3547    <li><p>If its <a href="#parent-element">parent element</a> is null, return null and
  3548    terminate these steps.
  3549 
  3550    <li><p>Return the result of running <a href="#locate-a-namespace">locate a namespace</a> on
  3551    its <a href="#parent-element">parent element</a> using <var title="">prefix</var>.
  3552   </ol>
  3553 
  3554  <!--AttrExodus <code>Attr</code> -->
  3555  <dt><code><a href="#document">Document</a></code>
  3556  <dd>
  3557   <ol>
  3558    <li><p>If its <a href="#document-element">document element</a> is null, return null and
  3559    terminate these steps.
  3560 
  3561    <li><p>Return the result of running <a href="#locate-a-namespace">locate a namespace</a> on
  3562    its <a href="#document-element">document element</a> using <var title="">prefix</var>.
  3563   </ol>
  3564 
  3565  <dt><code><a href="#documenttype">DocumentType</a></code>
  3566  <dt><code><a href="#documentfragment">DocumentFragment</a></code>
  3567  <dd><p>Return null.
  3568 
  3569  <dt>Any other node
  3570  <dd>
  3571   <ol>
  3572    <li><p>If its <a href="#parent-element">parent element</a> is null, return null and
  3573    terminate these steps.
  3574 
  3575    <li><p>Return the result of running <a href="#locate-a-namespace">locate a namespace</a> on
  3576    its <a href="#parent-element">parent element</a> using <var title="">prefix</var>.
  3577   </ol>
  3578 </dl>
  3579 
  3580 <p>The
  3581 <dfn id="dom-node-lookupprefix" title="dom-Node-lookupPrefix"><code>lookupPrefix(<var title="">namespace</var>)</code></dfn>
  3582 method must run these steps:
  3583 
  3584 <ol>
  3585  <li><p>If <var title="">namespace</var> is null or the empty string, return null.
  3586 
  3587  <li>
  3588   <p>Otherwise it depends on the <a href="#context-object">context object</a>:
  3589 
  3590   <dl class="switch">
  3591    <dt><code><a href="#element">Element</a></code>
  3592    <dd><p>Return the result of
  3593    <a href="#locate-a-namespace-prefix" title="locate a namespace prefix">locating a namespace prefix</a>
  3594    for the node using <var title="">namespace</var>.
  3595 
  3596    <!--AttrExodus <code>Attr</code> -->
  3597    <dt><code><a href="#document">Document</a></code>
  3598    <dd><p>Return the result of
  3599    <a href="#locate-a-namespace-prefix" title="locate a namespace prefix">locating a namespace prefix</a>
  3600    for its <a href="#document-element">document element</a>, if that is not null, or null
  3601    otherwise.
  3602 
  3603    <dt><code><a href="#documenttype">DocumentType</a></code>
  3604    <dt><code><a href="#documentfragment">DocumentFragment</a></code>
  3605    <dd><p>Return null.
  3606 
  3607    <dt>Any other node
  3608    <dd><p>Return the result of
  3609    <a href="#locate-a-namespace-prefix" title="locate a namespace prefix">locating a namespace prefix</a>
  3610    for its <a href="#parent-element">parent element</a>, or if that is null, null.
  3611   </dl>
  3612 </ol>
  3613 
  3614 <p>The
  3615 <dfn id="dom-node-lookupnamespaceuri" title="dom-Node-lookupNamespaceURI"><code>lookupNamespaceURI(<var title="">prefix</var>)</code></dfn>
  3616 method must run these steps:
  3617 
  3618 <ol>
  3619  <li><p>If <var title="">prefix</var> is the empty string, set it to null.
  3620 
  3621  <li><p>Return the result of running <a href="#locate-a-namespace">locate a namespace</a> for the
  3622  <a href="#context-object">context object</a> using <var title="">prefix</var>.
  3623 </ol>
  3624 
  3625 <p>The
  3626 <dfn id="dom-node-isdefaultnamespace" title="dom-Node-isDefaultNamespace"><code>isDefaultNamespace(<var title="">namespace</var>)</code></dfn>
  3627 method must run these steps:
  3628 
  3629 <ol>
  3630  <li><p>If <var title="">namespace</var> is the empty string, set it to null.
  3631 
  3632  <li><p>Let <var title="">defaultNamespace</var> be the result of running
  3633  <a href="#locate-a-namespace">locate a namespace</a> for the <a href="#context-object">context object</a> using
  3634  null.
  3635 
  3636  <li><p>Return true if <var title="">defaultNamespace</var> is the same as
  3637  <var title="">namespace</var>, or false otherwise.
  3638 </ol>
  3639 
  3640 <hr><!-- Collections -->
  3641 
  3642 <p>The
  3643 <dfn id="concept-getelementsbytagname" title="concept-getElementsByTagName">list of elements with local name <var title="">localName</var></dfn>
  3644 for a <a href="#concept-node" title="concept-node">node</a> <var title="">root</var> is the
  3645 <code><a href="#htmlcollection">HTMLCollection</a></code> returned by the following algorithm:
  3646 <ol>
  3647  <li><p>If <var title="">localName</var> is "<code>*</code>" (U+002A),
  3648  return a <code><a href="#htmlcollection">HTMLCollection</a></code> rooted at <var title="">root</var>,
  3649  whose filter matches only <a href="#concept-element" title="concept-element">elements</a>.
  3650 
  3651  <li>
  3652   <p>Otherwise, if <var title="">root</var>'s
  3653   <a href="#concept-node-document" title="concept-node-document">node document</a> is an
  3654   <a href="#html-document">HTML document</a>, return a <code><a href="#htmlcollection">HTMLCollection</a></code> rooted at
  3655   <var title="">root</var>, whose filter matches only the following
  3656   <a href="#concept-element" title="concept-element">elements</a>:
  3657 
  3658   <ul>
  3659    <li>Whose <a href="#concept-element-namespace" title="concept-element-namespace">namespace</a> is the
  3660    <a href="#html-namespace">HTML namespace</a> and whose
  3661    <a href="#concept-element-local-name" title="concept-element-local-name">local name</a> is
  3662    <var title="">localName</var> <a href="#converted-to-ascii-lowercase">converted to ASCII lowercase</a>.
  3663 
  3664    <li>Whose <a href="#concept-element-namespace" title="concept-element-namespace">namespace</a> is
  3665    <em>not</em> the <a href="#html-namespace">HTML namespace</a> and whose
  3666    <a href="#concept-element-local-name" title="concept-element-local-name">local name</a> is
  3667    <var title="">localName</var>.
  3668   </ul>
  3669 
  3670  <li><p>Otherwise, return a <code><a href="#htmlcollection">HTMLCollection</a></code> rooted at
  3671  <var title="">root</var>, whose filter matches only
  3672  <a href="#concept-element" title="concept-element">elements</a> whose
  3673  <a href="#concept-element-local-name" title="concept-element-local-name">local name</a> is
  3674  <var title="">localName</var>.
  3675 </ol>
  3676 
  3677 <p>When invoked with the same argument, the same <code><a href="#htmlcollection">HTMLCollection</a></code>
  3678 object may be returned as returned by an earlier call.
  3679 
  3680 
  3681 <p>The
  3682 <dfn id="concept-getelementsbytagnamens" title="concept-getElementsByTagNameNS">list of elements with namespace <var title="">namespace</var> and local name <var title="">localName</var></dfn>
  3683 for a <a href="#concept-node" title="concept-node">node</a> <var title="">root</var> is the
  3684 <code><a href="#htmlcollection">HTMLCollection</a></code> returned by the following algorithm:
  3685 <ol>
  3686  <li><p>If <var title="">namespace</var> is the empty string, set it to null.
  3687 
  3688  <li><p>If both <var title="">namespace</var> and <var title="">localName</var>
  3689  are "<code>*</code>" (U+002A) return a <code><a href="#htmlcollection">HTMLCollection</a></code> rooted at
  3690  <var title="">root</var>, whose filter matches only
  3691  <a href="#concept-element" title="concept-element">elements</a>.
  3692 
  3693  <li><p>Otherwise, if just <var title="">namespace</var> is "<code>*</code>"
  3694  (U+002A), return a <code><a href="#htmlcollection">HTMLCollection</a></code> rooted at
  3695  <var title="">root</var>, whose filter matches only
  3696  <a href="#concept-element" title="concept-element">elements</a> whose
  3697  <a href="#concept-element-local-name" title="concept-element-local-name">local name</a> is
  3698  <var title="">localName</var>.
  3699 
  3700  <li><p>Otherwise, if just <var title="">localName</var> is "<code>*</code>"
  3701  (U+002A), return a <code><a href="#htmlcollection">HTMLCollection</a></code> rooted at
  3702  <var title="">root</var>, whose filter matches only
  3703  <a href="#concept-element" title="concept-element">elements</a> whose
  3704  <a href="#concept-element-namespace" title="concept-element-namespace">namespace</a> is
  3705  <var title="">namespace</var>.
  3706 
  3707  <li><p>Otherwise, return a <code><a href="#htmlcollection">HTMLCollection</a></code> rooted at
  3708  <var title="">root</var>, whose filter matches only
  3709  <a href="#concept-element" title="concept-element">elements</a> whose
  3710  <a href="#concept-element-namespace" title="concept-element-namespace">namespace</a> is
  3711  <var title="">namespace</var> and
  3712  <a href="#concept-element-local-name" title="concept-element-local-name">local name</a> is
  3713  <var title="">localName</var>.
  3714 </ol>
  3715 
  3716 <p>When invoked with the same arguments, the same <code><a href="#htmlcollection">HTMLCollection</a></code>
  3717 object may be returned as returned by an earlier call.
  3718 
  3719 
  3720 <p>The
  3721 <dfn id="concept-getelementsbyclassname" title="concept-getElementsByClassName">list of elements with class names <var title="">classNames</var></dfn>
  3722 for a <a href="#concept-node" title="concept-node">node</a> <var title="">root</var> is the
  3723 <code><a href="#htmlcollection">HTMLCollection</a></code> returned by the following algorithm:
  3724 <ol>
  3725  <li>
  3726   <p>Let <var title="">classes</var> be the set of tokens found by
  3727   <a href="#split-a-string-on-spaces" title="split a string on spaces">splitting</a>
  3728   <var title="">classNames</var> on spaces. (Duplicates are ignored.)
  3729 
  3730  <li>
  3731   <p>If <var title="">classes</var> is the empty set, return an empty
  3732   <code><a href="#htmlcollection">HTMLCollection</a></code> and terminate these steps.
  3733 
  3734  <li>
  3735   <p>Return a <code><a href="#htmlcollection">HTMLCollection</a></code> rooted at <var title="">root</var>,
  3736   whose filter matches only
  3737   <a href="#concept-element" title="concept-element">elements</a> that have all the
  3738   <a href="#concept-class" title="concept-class">classes</a> in <var title="">classes</var>.
  3739 
  3740   <p>If <var title="">root</var>'s
  3741   <a href="#concept-node-document" title="concept-node-document">node document</a> is in
  3742   <a href="#concept-document-quirks" title="concept-document-quirks">quirks mode</a>, then the
  3743   comparisons for the <a href="#concept-class" title="concept-class">classes</a> must be done
  3744   in an <a href="#ascii-case-insensitive">ASCII case-insensitive</a> manner, or in a
  3745   <a href="#case-sensitive">case-sensitive</a> manner otherwise.
  3746 </ol>
  3747 <p>When invoked with the same argument, the same <code><a href="#htmlcollection">HTMLCollection</a></code>
  3748 object may be returned as returned by an earlier call.
  3749 
  3750 
  3751 
  3752 <h3 id="interface-document"><span class="secno">5.5 </span>Interface <code><a href="#document">Document</a></code></h3>
  3753 <pre class="idl">[<a href="#dom-document" title="dom-Document">Constructor</a>]
  3754 interface <dfn id="document">Document</dfn> : <a href="#node">Node</a> {
  3755   readonly attribute <a href="#domimplementation">DOMImplementation</a> <a href="#dom-document-implementation" title="dom-Document-implementation">implementation</a>;
  3756   readonly attribute DOMString <a href="#dom-document-url" title="dom-Document-URL">URL</a>;
  3757   readonly attribute DOMString <a href="#dom-document-documenturi" title="dom-Document-documentURI">documentURI</a>;
  3758   readonly attribute DOMString <a href="#dom-document-compatmode" title="dom-Document-compatMode">compatMode</a>;
  3759   readonly attribute DOMString <a href="#dom-document-characterset" title="dom-Document-characterSet">characterSet</a>;
  3760   readonly attribute DOMString <a href="#dom-document-contenttype" title="dom-Document-contentType">contentType</a>;
  3761 
  3762   readonly attribute <a href="#documenttype">DocumentType</a>? <a href="#dom-document-doctype" title="dom-Document-doctype">doctype</a>;
  3763   readonly attribute <a href="#element">Element</a>? <a href="#dom-document-documentelement" title="dom-Document-documentElement">documentElement</a>;
  3764   <a href="#htmlcollection">HTMLCollection</a> <a href="#dom-document-getelementsbytagname" title="dom-Document-getElementsByTagName">getElementsByTagName</a>(DOMString <var title="">localName</var>);
  3765   <a href="#htmlcollection">HTMLCollection</a> <a href="#dom-document-getelementsbytagnamens" title="dom-Document-getElementsByTagNameNS">getElementsByTagNameNS</a>(DOMString? <var title="">namespace</var>, DOMString <var title="">localName</var>);
  3766   <a href="#htmlcollection">HTMLCollection</a> <a href="#dom-document-getelementsbyclassname" title="dom-Document-getElementsByClassName">getElementsByClassName</a>(DOMString <var title="">classNames</var>);
  3767   <a href="#element">Element</a>? <a href="#dom-document-getelementbyid" title="dom-Document-getElementById">getElementById</a>(DOMString <var title="">elementId</var>);
  3768 
  3769   <a href="#element">Element</a> <a href="#dom-document-createelement" title="dom-Document-createElement">createElement</a>(DOMString <var title="">localName</var>);
  3770   <a href="#element">Element</a> <a href="#dom-document-createelementns" title="dom-Document-createElementNS">createElementNS</a>(DOMString? <var title="">namespace</var>, DOMString <var title="">qualifiedName</var>);
  3771   <a href="#documentfragment">DocumentFragment</a> <a href="#dom-document-createdocumentfragment" title="dom-Document-createDocumentFragment">createDocumentFragment</a>();
  3772   <a href="#text">Text</a> <a href="#dom-document-createtextnode" title="dom-Document-createTextNode">createTextNode</a>(DOMString <var title="">data</var>);
  3773   <a href="#comment">Comment</a> <a href="#dom-document-createcomment" title="dom-Document-createComment">createComment</a>(DOMString <var title="">data</var>);
  3774   <a href="#processinginstruction">ProcessingInstruction</a> <a href="#dom-document-createprocessinginstruction" title="dom-Document-createProcessingInstruction">createProcessingInstruction</a>(DOMString <var title="">target</var>, DOMString <var title="">data</var>);<!--
  3775   CDATASection createCDATASection(DOMString data);
  3776   EntityReference createEntityReference(DOMString name);
  3777   <span>Attr</span> <span title=dom-Document-createAttribute>createAttribute</span>(DOMString name);
  3778   <span>Attr</span> <span title=dom-Document-createAttributeNS>createAttributeNS</span>(DOMString namespace, DOMString qualifiedName);
  3779     If adding this, search for [createAttribute]-->
  3780 
  3781   <a href="#node">Node</a> <a href="#dom-document-importnode" title="dom-Document-importNode">importNode</a>(<a href="#node">Node</a> <var title="">node</var>, optional boolean <var title="">deep</var> = true);
  3782   <a href="#node">Node</a> <a href="#dom-document-adoptnode" title="dom-Document-adoptNode">adoptNode</a>(<a href="#node">Node</a> <var title="">node</var>);
  3783 
  3784   <a href="#event">Event</a> <a href="#dom-document-createevent" title="dom-Document-createEvent">createEvent</a>(DOMString <var title="">interface</var>);
  3785 
  3786   <a href="#range">Range</a> <a href="#dom-document-createrange" title="dom-Document-createRange">createRange</a>();
  3787 
  3788   // <a href="#nodefilter">NodeFilter</a>.<a href="#dom-nodefilter-show_all" title="dom-NodeFilter-SHOW_ALL">SHOW_ALL</a> = 0xFFFFFFFF
  3789   <a href="#nodeiterator">NodeIterator</a> <a href="#dom-document-createnodeiterator" title="dom-Document-createNodeIterator">createNodeIterator</a>(<!--
  3790   --><a href="#node">Node</a> <var title="">root</var>, <!--
  3791   -->optional unsigned long <var title="">whatToShow</var> = 0xFFFFFFFF, <!--
  3792   -->optional <a href="#nodefilter">NodeFilter</a>? <var title="">filter</var> = null);
  3793   <a href="#treewalker">TreeWalker</a> <a href="#dom-document-createtreewalker" title="dom-Document-createTreeWalker">createTreeWalker</a>(<!--
  3794   --><a href="#node">Node</a> <var title="">root</var>, <!--
  3795   -->optional unsigned long <var title="">whatToShow</var> = 0xFFFFFFFF, <!--
  3796   -->optional <a href="#nodefilter">NodeFilter</a>? <var title="">filter</var> = null);
  3797 
  3798   // NEW
  3799   void <a href="#dom-rootnode-prepend" title="dom-RootNode-prepend">prepend</a>((<a href="#node">Node</a> or DOMString)... <var title="">nodes</var>);
  3800   void <a href="#dom-rootnode-append" title="dom-RootNode-append">append</a>((<a href="#node">Node</a> or DOMString)... <var title="">nodes</var>);
  3801 };
  3802 
  3803 interface <dfn id="xmldocument">XMLDocument</dfn> : <a href="#document">Document</a> {};</pre>
  3804 
  3805 <p><code><a href="#document">Document</a></code> <a href="#concept-node" title="concept-node">nodes</a> are simply
  3806 known as <dfn id="concept-document" title="concept-document">documents</dfn>.
  3807 
  3808 <p>Each <a href="#concept-document" title="concept-document">document</a> has an associated
  3809 <dfn id="concept-document-encoding" title="concept-document-encoding">encoding</dfn>,
  3810 <dfn id="concept-document-content-type" title="concept-document-content-type">content type</dfn>, and
  3811 <dfn id="concept-document-url" title="concept-document-url">URL</dfn>.
  3812 
  3813 <p>Unless explicitly given when a
  3814 <a href="#concept-document" title="concept-document">document</a> is created its
  3815 <a href="#concept-document-encoding" title="concept-document-encoding">encoding</a> is the
  3816 <code class="external" data-anolis-spec="encoding"><a href="http://encoding.spec.whatwg.org/#utf-8">utf-8</a></code>
  3817 <a class="external" data-anolis-spec="encoding" href="http://encoding.spec.whatwg.org/#encoding">encoding</a>, its
  3818 <a href="#concept-document-content-type" title="concept-document-content-type">content type</a> is
  3819 "<code title="">application/xml</code>", and its
  3820 <a href="#concept-document-url" title="concept-document-url">URL</a> is
  3821 "<code title="">about:blank</code>".
  3822 
  3823 <p>A <a href="#concept-document" title="concept-document">document</a> is assumed to be an
  3824 <dfn id="xml-document">XML document</dfn> unless it is flagged as being an
  3825 <dfn id="html-document">HTML document</dfn>. Whether a
  3826 <a href="#concept-document" title="concept-document">document</a> is an
  3827 <a href="#html-document">HTML document</a> or an <a href="#xml-document">XML document</a> affects the
  3828 behavior of certain APIs.
  3829 
  3830 <p>A <a href="#concept-document" title="concept-document">document</a> is always set to one of
  3831 three modes: <dfn id="concept-document-no-quirks" title="concept-document-no-quirks">no-quirks mode</dfn>, the
  3832 default; <dfn id="concept-document-quirks" title="concept-document-quirks">quirks mode</dfn>, used
  3833 typically for legacy documents; and
  3834 <dfn id="concept-document-limited-quirks" title="concept-document-limited-quirks">limited-quirks mode</dfn>. Unless
  3835 <a href="#other-applicable-specifications">other applicable specifications</a> define otherwise, a
  3836 <a href="#concept-document" title="concept-document">document</a> must be in
  3837 <a href="#concept-document-no-quirks" title="concept-document-no-quirks">no-quirks mode</a>.
  3838 
  3839 <p class="note">The mode is only ever changed from the default if the
  3840 <a href="#concept-document" title="concept-document">document</a> is created by the
  3841 <a class="external" data-anolis-spec="html" href="http://www.whatwg.org/specs/web-apps/current-work/multipage/parsing.html#html-parser">HTML parser</a>, based on the presence,
  3842 absence, or value of the DOCTYPE string.
  3843 <a class="informative" href="#refsHTML">[HTML]</a>
  3844 
  3845 <p class="note"><a href="#concept-document-no-quirks" title="concept-document-no-quirks">No-quirks mode</a>
  3846 was originally known as "standards mode" and
  3847 <a href="#concept-document-limited-quirks" title="concept-document-limited-quirks">limited-quirks mode</a> was
  3848 once known as "almost standards mode". They have been renamed because their
  3849 details are now defined by standards. (And because Ian Hickson vetoed their
  3850 original names on the basis that they are nonsensical.)
  3851 
  3852 <hr>
  3853 
  3854 <dl class="domintro">
  3855  <dt><code><var title="">document</var> = new <a href="#dom-document" title="dom-Document">Document</a>()</code>
  3856  <dd><p>Returns a new <a href="#concept-document" title="concept-document">document</a>.
  3857 
  3858  <dt><var title="">document</var> . <code title="dom-Document-implementation"><a href="#dom-document-implementation">implementation</a></code>
  3859  <dd><p>Returns the associated <code><a href="#domimplementation">DOMImplementation</a></code> object.
  3860 
  3861  <dt><var title="">document</var> . <code title="dom-Document-URL"><a href="#dom-document-url">URL</a></code>
  3862  <dt><var title="">document</var> . <code title="dom-Document-documentURI"><a href="#dom-document-documenturi">documentURI</a></code>
  3863  <dd><p>Returns the <a href="#concept-document-url" title="concept-document-url">URL</a>.
  3864 
  3865  <dt><var title="">document</var> . <code title="dom-Document-compatMode"><a href="#dom-document-compatmode">compatMode</a></code>
  3866  <dd>
  3867   <p>Returns the string "<code title="">CSS1Compat</code>" if
  3868   <var title="">document</var> is in
  3869   <a href="#concept-document-no-quirks" title="concept-document-no-quirks">no-quirks mode</a> or
  3870   <a href="#concept-document-limited-quirks" title="concept-document-limited-quirks">limited-quirks mode</a>, and
  3871   "<code title="">BackCompat</code>", if <var title="">document</var> is in
  3872   <a href="#concept-document-quirks" title="concept-document-quirks">quirks mode</a>.
  3873 
  3874  <dt><var title="">document</var> . <code title="dom-Document-characterSet"><a href="#dom-document-characterset">characterSet</a></code>
  3875  <dd><p>Returns the <a href="#concept-document-encoding" title="concept-document-encoding">encoding</a>.
  3876 
  3877  <dt><var title="">document</var> . <code title="dom-Document-contentType"><a href="#dom-document-contenttype">contentType</a></code>
  3878  <dd><p>Returns the
  3879  <a href="#concept-document-content-type" title="concept-document-content-type">content type</a>.
  3880 </dl>
  3881 
  3882 <p>The <dfn id="dom-document" title="dom-Document"><code>Document()</code></dfn> constructor
  3883 must return a new <a href="#concept-document" title="concept-document">document</a>.
  3884 
  3885 <p class="note">Unlike
  3886 <code title="dom-DOMImplementation-createDocument"><a href="#dom-domimplementation-createdocument">createDocument()</a></code>
  3887 this constructor does not return an <code><a href="#xmldocument">XMLDocument</a></code> object, but a
  3888 <a href="#concept-document" title="concept-document">document</a> (<code><a href="#document">Document</a></code> object).
  3889 
  3890 <p>The
  3891 <dfn id="dom-document-implementation" title="dom-Document-implementation"><code>implementation</code></dfn>
  3892 attribute must return the <code><a href="#domimplementation">DOMImplementation</a></code> object that is
  3893 associated with the <a href="#concept-document" title="concept-document">document</a>.
  3894 
  3895 <p>The <dfn id="dom-document-url" title="dom-Document-URL"><code>URL</code></dfn> and
  3896 <dfn id="dom-document-documenturi" title="dom-Document-documentURI"><code>documentURI</code></dfn>
  3897 attributes must return the <a href="#concept-document-url" title="concept-document-url">URL</a>.
  3898 
  3899 <p>The <dfn id="dom-document-compatmode" title="dom-Document-compatMode"><code>compatMode</code></dfn>
  3900 attribute must return "<code title="">BackCompat</code>" if the
  3901 <a href="#context-object">context object</a> is in
  3902 <a href="#concept-document-quirks" title="concept-document-quirks">quirks mode</a>, or
  3903 "<code title="">CSS1Compat</code>" otherwise.
  3904 
  3905 <p>The <dfn id="dom-document-characterset" title="dom-Document-characterSet"><code>characterSet</code></dfn>
  3906 attribute must return the <a class="external" data-anolis-spec="encoding" href="http://encoding.spec.whatwg.org/#name">name</a> of the
  3907 <a href="#concept-document-encoding" title="concept-document-encoding">encoding</a>.
  3908 
  3909 <p>The <dfn id="dom-document-contenttype" title="dom-Document-contentType"><code>contentType</code></dfn>
  3910 attribute must return the
  3911 <a href="#concept-document-content-type" title="concept-document-content-type">content type</a>.
  3912 
  3913 <hr>
  3914 
  3915 <dl class="domintro">
  3916  <dt><var title="">document</var> . <code title="dom-Document-doctype"><a href="#dom-document-doctype">doctype</a></code>
  3917  <dd><p>Returns the <a href="#concept-doctype" title="concept-doctype">doctype</a> or null if
  3918  there is none.
  3919 
  3920  <dt><var title="">document</var> . <code title="dom-Document-documentElement"><a href="#dom-document-documentelement">documentElement</a></code>
  3921  <dd><p>Returns the <a href="#document-element">document element</a>.
  3922 
  3923  <dt><var title="">collection</var> = <var title="">document</var> . <code title="dom-Document-getElementsByTagName"><a href="#dom-document-getelementsbytagname">getElementsByTagName(<var>localName</var>)</a></code>
  3924 
  3925  <dd>
  3926   <p>If <var>localName</var> is "<code title="">*</code>" returns a
  3927   <code><a href="#htmlcollection">HTMLCollection</a></code> of all
  3928   <a href="#concept-tree-descendant" title="concept-tree-descendant">descendant</a>
  3929   <a href="#concept-element" title="concept-element">elements</a>.
  3930 
  3931   <p>Otherwise, returns a <code><a href="#htmlcollection">HTMLCollection</a></code> of all
  3932   <a href="#concept-tree-descendant" title="concept-tree-descendant">descendant</a>
  3933   <a href="#concept-element" title="concept-element">elements</a> whose
  3934   <a href="#concept-element-local-name" title="concept-element-local-name">local name</a> is
  3935   <var title="">localName</var>. (Matches case-insensitively against
  3936   <a href="#concept-element" title="concept-element">elements</a> in the
  3937   <a href="#html-namespace">HTML namespace</a> within an <a href="#html-document">HTML document</a>.)
  3938 
  3939  <dt><var title="">collection</var> = <var title="">document</var> . <code title="dom-Document-getElementsByTagName"><a href="#dom-document-getelementsbytagname">getElementsByTagNameNS(<var>namespace</var>, <var>localName</var>)</a></code>
  3940 
  3941  <dd>
  3942   <p>If <var>namespace</var> and <var>localName</var> are
  3943   "<code title="">*</code>" returns a <code><a href="#htmlcollection">HTMLCollection</a></code> of all
  3944   <a href="#concept-tree-descendant" title="concept-tree-descendant">descendant</a>
  3945   <a href="#concept-element" title="concept-element">elements</a>.
  3946 
  3947   <p>If only <var>namespace</var> is "<code title="">*</code>" returns a
  3948   <code><a href="#htmlcollection">HTMLCollection</a></code> of all
  3949   <a href="#concept-tree-descendant" title="concept-tree-descendant">descendant</a>
  3950   <a href="#concept-element" title="concept-element">elements</a> whose
  3951   <a href="#concept-element-local-name" title="concept-element-local-name">local name</a> is
  3952   <var title="">localName</var>.
  3953 
  3954   <p>If only <var>localName</var> is "<code title="">*</code>" returns a
  3955   <code><a href="#htmlcollection">HTMLCollection</a></code> of all
  3956   <a href="#concept-tree-descendant" title="concept-tree-descendant">descendant</a>
  3957   <a href="#concept-element" title="concept-element">elements</a> whose
  3958   <a href="#concept-element-namespace" title="concept-element-namespace">namespace</a> is
  3959   <var title="">namespace</var>.
  3960 
  3961   <p>Otherwise, returns a <code><a href="#htmlcollection">HTMLCollection</a></code> of all
  3962   <a href="#concept-tree-descendant" title="concept-tree-descendant">descendant</a>
  3963   <a href="#concept-element" title="concept-element">elements</a> whose
  3964   <a href="#concept-element-namespace" title="concept-element-namespace">namespace</a> is
  3965   <var title="">namespace</var> and
  3966   <a href="#concept-element-local-name" title="concept-element-local-name">local name</a> is
  3967   <var title="">localName</var>.
  3968 
  3969  <dt><var title="">collection</var> = <var title="">document</var> . <code title="dom-Document-getElementsByClassName"><a href="#dom-document-getelementsbyclassname">getElementsByClassName(<var>classes</var>)</a></code>
  3970  <dt><var title="">collection</var> = <var title="">element</var> . <code title="dom-Element-getElementsByClassName"><a href="#dom-element-getelementsbyclassname">getElementsByClassName(<var>classes</var>)</a></code>
  3971  <dd>
  3972   <p>Returns a <code><a href="#htmlcollection">HTMLCollection</a></code> of the
  3973   <a href="#concept-element" title="concept-element">elements</a> in the object on which
  3974   the method was invoked (a <a href="#concept-document" title="concept-document">document</a> or
  3975   an <a href="#concept-element" title="concept-element">element</a>) that have all the classes
  3976   given by <var title="">classes</var>.
  3977   <p>The <var title="">classes</var> argument is interpreted as a
  3978   space-separated list of classes.
  3979 
  3980  <dt><var title="">element</var> = <var title="">document</var> . <code title="dom-Document-getElementById"><a href="#dom-document-getelementbyid">getElementById(<var title="">elementId</var>)</a></code>
  3981  <dd><p>Returns the first <a href="#concept-element" title="concept-element">element</a> in
  3982  <var title="">document</var> with the given <a href="#concept-id" title="concept-id">ID</a>.
  3983 </dl>
  3984 
  3985 <p>The <dfn id="dom-document-doctype" title="dom-Document-doctype"><code>doctype</code></dfn> attribute
  3986 must return the <a href="#concept-tree-child" title="concept-tree-child">child</a> of the
  3987 <a href="#concept-document" title="concept-document">document</a> that is a
  3988 <a href="#concept-doctype" title="concept-doctype">doctype</a>, or null otherwise.
  3989 
  3990 <p>The
  3991 <dfn id="dom-document-documentelement" title="dom-Document-documentElement"><code>documentElement</code></dfn>
  3992 attribute must return the <a href="#document-element">document element</a>.
  3993 
  3994 <p>The
  3995 <dfn id="dom-document-getelementsbytagname" title="dom-Document-getElementsByTagName"><code>getElementsByTagName(<var title="">localName</var>)</code></dfn>
  3996 method must return the
  3997 <a href="#concept-getelementsbytagname" title="concept-getElementsByTagName">list of elements with local name <var title="">localName</var></a>
  3998 for the <a href="#context-object">context object</a>.
  3999 
  4000 <p class="note">Thus, in an <a href="#html-document">HTML document</a>,
  4001 <code title="">document.getElementsByTagName("FOO")</code> will match
  4002 <code title="">FOO</code> elements that are not in the
  4003 <a href="#html-namespace">HTML namespace</a>, and <code title="">foo</code> elements that are in
  4004 the <a href="#html-namespace">HTML namespace</a>, but not <code title="">FOO</code> elements
  4005 that are in the <a href="#html-namespace">HTML namespace</a>.
  4006 
  4007 
  4008 <p>The
  4009 <dfn id="dom-document-getelementsbytagnamens" title="dom-Document-getElementsByTagNameNS"><code>getElementsByTagNameNS(<var title="">namespace</var>, <var title="">localName</var>)</code></dfn>
  4010 method must return the
  4011 <a href="#concept-getelementsbytagnamens" title="concept-getElementsByTagNameNS">list of elements with namespace <var title="">namespace</var> and local name <var title="">localName</var></a>
  4012 for the <a href="#context-object">context object</a>.
  4013 
  4014 
  4015 <p>The
  4016 <dfn id="dom-document-getelementsbyclassname" title="dom-Document-getElementsByClassName"><code>getElementsByClassName(<var>classNames</var>)</code></dfn>
  4017 method must return the
  4018 <a href="#concept-getelementsbyclassname" title="concept-getElementsByClassName">list of elements with class names <var title="">classNames</var></a>
  4019 for the <a href="#context-object">context object</a>.
  4020 
  4021 <div class="example">
  4022  <p>Given the following XHTML fragment:
  4023 
  4024  <pre>&lt;div id="example"&gt;
  4025   &lt;p id="p1" class="aaa bbb"/&gt;
  4026   &lt;p id="p2" class="aaa ccc"/&gt;
  4027   &lt;p id="p3" class="bbb ccc"/&gt;
  4028 &lt;/div&gt;</pre>
  4029 
  4030  <p>A call to
  4031  <code title="">document.getElementById('example').getElementsByClassName('aaa')</code>
  4032  would return a <code><a href="#htmlcollection">HTMLCollection</a></code> with the two paragraphs
  4033  <code title="">p1</code> and <code title="">p2</code> in it.
  4034 
  4035  <p>A call to
  4036  <code title="">getElementsByClassName('ccc bbb')</code>
  4037  would only return one node, however, namely <code title="">p3</code>. A call to
  4038  <code title="">document.getElementById('example').getElementsByClassName('bbb  ccc ')</code>
  4039  would return the same thing.
  4040 
  4041  <p>A call to
  4042  <code title="">getElementsByClassName('aaa,bbb')</code>
  4043  would return no nodes; none of the elements above are in the
  4044  <code title="">aaa,bbb</code> class.
  4045 </div>
  4046 
  4047 <!-- v2:
  4048 >         * xGetParentElementByClassName(rootElement, className, tagName) -
  4049 > Navigates upwards until we hit a parent element with the given class name and
  4050 > optional tag name.
  4051 -->
  4052 
  4053 <p>The
  4054 <dfn id="dom-document-getelementbyid" title="dom-Document-getElementById"><code>getElementById(<var title="">elementId</var>)</code></dfn>
  4055 method must return the first <a href="#concept-element" title="concept-element">element</a>, in
  4056 <a href="#concept-tree-order" title="concept-tree-order">tree order</a>, within the
  4057 <a href="#context-object">context object</a>'s <a href="#concept-tree" title="concept-tree">tree</a>, whose
  4058 <a href="#concept-id" title="concept-ID">ID</a> is <var title="">elementId</var>, or null if
  4059 there is none.
  4060 
  4061 <hr>
  4062 
  4063 <dl class="domintro">
  4064  <dt><var title="">element</var> = <var title="">document</var> . <code title="dom-Document-createElement"><a href="#dom-document-createelement">createElement(<var>localName</var>)</a></code>
  4065  <dd>
  4066   <p>Returns an <a href="#concept-element" title="concept-element">element</a> in the
  4067   <a href="#html-namespace">HTML namespace</a> with <var title="">localName</var> as
  4068   <a href="#concept-element-local-name" title="concept-element-local-name">local name</a>. (In an
  4069   <a href="#html-document">HTML document</a> <var title="">localName</var> is lowercased.)
  4070 
  4071   <p>If <var title="">localName</var> does not match the
  4072   <code class="external" data-anolis-spec="xml"><a href="http://www.w3.org/TR/xml/#NT-Name">Name</a></code> production an
  4073   "<code><a href="#invalidcharactererror">InvalidCharacterError</a></code>"
  4074   exception will be thrown.
  4075 
  4076  <dt><var title="">element</var> = <var title="">document</var> . <code title="dom-Document-createElement"><a href="#dom-document-createelement">createElementNS(<var>namespace</var>, <var>qualifiedName</var>)</a></code>
  4077 
  4078  <dd>
  4079   <p>Returns an <a href="#concept-element" title="concept-element">element</a> with
  4080   <a href="#concept-element-namespace" title="concept-element-namespace">namespace</a>
  4081   <var title="">namespace</var>. Its
  4082   <a href="#concept-element-namespace-prefix" title="concept-element-namespace-prefix">namespace prefix</a> will
  4083   be everything before "<code title="">:</code>" (U+003E) in
  4084   <var title="">qualifiedName</var> or null. Its
  4085   <a href="#concept-element-local-name" title="concept-element-local-name">local name</a> will be
  4086   everything after "<code title="">:</code>" (U+003E) in
  4087   <var title="">qualifiedName</var> or <var title="">qualifiedName</var>.
  4088 
  4089   <p>If <var title="">localName</var> does not match the
  4090   <code class="external" data-anolis-spec="xml"><a href="http://www.w3.org/TR/xml/#NT-Name">Name</a></code> production an
  4091   "<code><a href="#invalidcharactererror">InvalidCharacterError</a></code>"
  4092   exception will be thrown.
  4093 
  4094   <p>If one of the following conditions is true a
  4095   "<code><a href="#namespaceerror">NamespaceError</a></code>" exception
  4096   will be thrown:
  4097 
  4098   <ul>
  4099    <li><var title="">localName</var> does not match the
  4100    <code class="external" data-anolis-spec="xmlns"><a href="http://www.w3.org/TR/xml-names/#NT-QName">QName</a></code> production.
  4101    <li><a href="#concept-element-namespace-prefix" title="concept-element-namespace-prefix">Namespace prefix</a>
  4102    is not null and <var title="">namespace</var> is the empty string.
  4103    <li><a href="#concept-element-namespace-prefix" title="concept-element-namespace-prefix">Namespace prefix</a>
  4104    is "<code title="">xml</code>" and <var title="">namespace</var> is not the
  4105    <a href="#xml-namespace">XML namespace</a>.
  4106    <li><var title="">qualifiedName</var> or
  4107    <a href="#concept-element-namespace-prefix" title="concept-element-namespace-prefix">namespace prefix</a>
  4108    is "<code title="">xmlns</code>" and <var title="">namespace</var> is not the
  4109    <a href="#xmlns-namespace">XMLNS namespace</a>.
  4110    <li><var title="">namespace</var> is the <a href="#xmlns-namespace">XMLNS namespace</a> and
  4111    neither <var title="">qualifiedName</var> nor
  4112    <a href="#concept-element-namespace-prefix" title="concept-element-namespace-prefix">namespace prefix</a>
  4113    is "<code title="">xmlns</code>".
  4114   </ul>
  4115 
  4116  <dt><var title="">documentFragment</var> = <var title="">document</var> . <code title="dom-Document-createDocumentFragment"><a href="#dom-document-createdocumentfragment">createDocumentFragment()</a></code>
  4117  <dd><p>Returns a <code><a href="#documentfragment">DocumentFragment</a></code>
  4118  <a href="#concept-node" title="concept-node">node</a>.
  4119 
  4120  <dt><var title="">text</var> = <var title="">document</var> . <code title="dom-Document-createTextNode"><a href="#dom-document-createtextnode">createTextNode(<var>data</var>)</a></code>
  4121  <dd><p>Returns a <code><a href="#text">Text</a></code> <a href="#concept-node" title="concept-node">node</a>
  4122  whose <a href="#concept-cd-data" title="concept-CD-data">data</a> is <var title="">data</var>.
  4123 
  4124  <dt><var title="">comment</var> = <var title="">document</var> . <code title="dom-Document-createComment"><a href="#dom-document-createcomment">createComment(<var>data</var>)</a></code>
  4125  <dd><p>Returns a <code><a href="#comment">Comment</a></code> <a href="#concept-node" title="concept-node">node</a>
  4126  whose <a href="#concept-cd-data" title="concept-CD-data">data</a> is <var title="">data</var>.
  4127 
  4128  <dt><var title="">processingInstruction</var> = <var title="">document</var> . <code title="dom-Document-createProcessingInstruction"><a href="#dom-document-createprocessinginstruction">createProcessingInstruction(<var>target</var>, <var>data</var>)</a></code>
  4129  <dd>
  4130   <p>Returns a <code><a href="#processinginstruction">ProcessingInstruction</a></code>
  4131   <a href="#concept-node" title="concept-node">node</a> whose
  4132   <a href="#concept-pi-target" title="concept-PI-target">target</a> is <var title="">target</var> and
  4133   <a href="#concept-cd-data" title="concept-CD-data">data</a> is <var title="">data</var>.
  4134   <p>If <var title="">target</var> does not match the
  4135   <code class="external" data-anolis-spec="xml"><a href="http://www.w3.org/TR/xml/#NT-Name">Name</a></code> production an
  4136   "<code><a href="#invalidcharactererror">InvalidCharacterError</a></code>"
  4137   exception will be thrown.
  4138   <p>If <var title="">data</var> contains "<code title="">?&gt;</code>" an
  4139   "<code><a href="#invalidcharactererror">InvalidCharacterError</a></code>"
  4140   exception will be thrown.
  4141 </dl>
  4142 
  4143 <p>The <dfn id="dom-document-createelement" title="dom-Document-createElement"><code>createElement(<var title="">localName</var>)</code></dfn> method must run the these steps:
  4144 
  4145 <ol>
  4146  <li><p>If <var title="">localName</var> does not match the
  4147  <code class="external" data-anolis-spec="xml"><a href="http://www.w3.org/TR/xml/#NT-Name">Name</a></code> production,
  4148  <a href="#concept-throw" title="concept-throw">throw</a> an
  4149  "<code><a href="#invalidcharactererror">InvalidCharacterError</a></code>" exception and terminate these
  4150  steps.
  4151 
  4152  <li><p>If the <a href="#context-object">context object</a> is an <a href="#html-document">HTML document</a>,
  4153  let <var title="">localName</var> be
  4154  <a href="#converted-to-ascii-lowercase">converted to ASCII lowercase</a>.
  4155  <!-- XXX why restrict this to HTML documents? -->
  4156 
  4157  <li><p>Return a new <a href="#concept-element" title="concept-element">element</a> with no
  4158  attributes, <a href="#concept-element-namespace" title="concept-element-namespace">namespace</a> set to
  4159  the <a href="#html-namespace">HTML namespace</a>,
  4160  <a href="#concept-element-local-name" title="concept-element-local-name">local name</a> set to
  4161  <var title="">localName</var>, and
  4162  <a href="#concept-node-document" title="concept-node-document">node document</a> set to the
  4163  <a href="#context-object">context object</a>.
  4164 </ol>
  4165 
  4166 <p>The
  4167 <dfn id="dom-document-createelementns" title="dom-Document-createElementNS"><code>createElementNS(<var title="">namespace</var>, <var title="">qualifiedName</var>)</code></dfn>
  4168 method must run these steps:
  4169 <ol>
  4170  <li><p>If <var title="">namespace</var> is the empty string, set it to null.
  4171 
  4172  <li><p>If <var title="">qualifiedName</var> does not match the
  4173  <code class="external" data-anolis-spec="xml"><a href="http://www.w3.org/TR/xml/#NT-Name">Name</a></code> production,
  4174  <a href="#concept-throw" title="concept-throw">throw</a> an
  4175  "<code><a href="#invalidcharactererror">InvalidCharacterError</a></code>" exception and terminate these
  4176  steps.
  4177  <li><p>If <var title="">qualifiedName</var> does not match the
  4178  <code class="external" data-anolis-spec="xmlns"><a href="http://www.w3.org/TR/xml-names/#NT-QName">QName</a></code> production,
  4179  <a href="#concept-throw" title="concept-throw">throw</a> a
  4180  "<code><a href="#namespaceerror">NamespaceError</a></code>" exception and terminate these steps.
  4181  <li><p>If <var title="">qualifiedName</var> contains a "<code>:</code>"
  4182  (U+003E), then split the string on it and let <var title="">prefix</var> be
  4183  the part before and <var title="">localName</var> the part after. Otherwise,
  4184  let <var title="">prefix</var> be null and <var title="">localName</var> be
  4185  <var title="">qualifiedName</var>.
  4186  <li><p>If <var title="">prefix</var> is not null and
  4187  <var title="">namespace</var> is null, <a href="#concept-throw" title="concept-throw">throw</a>
  4188  a "<code><a href="#namespaceerror">NamespaceError</a></code>" exception and terminate these steps.
  4189  <li><p>If <var title="">prefix</var> is "<code title="">xml</code>" and
  4190  <var title="">namespace</var> is not the <a href="#xml-namespace">XML namespace</a>,
  4191  <a href="#concept-throw" title="concept-throw">throw</a> a
  4192  "<code><a href="#namespaceerror">NamespaceError</a></code>" exception and terminate these steps.
  4193  <li><p>If <var title="">qualifiedName</var> or <var title="">prefix</var> is
  4194  "<code title="">xmlns</code>" and <var title="">namespace</var> is not the
  4195  <a href="#xmlns-namespace">XMLNS namespace</a>, <a href="#concept-throw" title="concept-throw">throw</a> a
  4196  "<code><a href="#namespaceerror">NamespaceError</a></code>" exception and terminate these steps.
  4197  <li><p>If <var title="">namespace</var> is the <a href="#xmlns-namespace">XMLNS namespace</a>
  4198  and neither <var title="">qualifiedName</var> nor <var title="">prefix</var> is
  4199  "<code title="">xmlns</code>", <a href="#concept-throw" title="concept-throw">throw</a> a
  4200  "<code><a href="#namespaceerror">NamespaceError</a></code>" exception and terminate these steps.
  4201  <li><p>Return a new <a href="#concept-element" title="concept-element">element</a> with no
  4202  attributes, <a href="#concept-element-namespace" title="concept-element-namespace">namespace</a> set to
  4203  <var title="">namespace</var>,
  4204  <a href="#concept-element-namespace-prefix" title="concept-element-namespace-prefix">namespace prefix</a> set to
  4205  <var title="">prefix</var>,
  4206  <a href="#concept-element-local-name" title="concept-element-local-name">local name</a> set to
  4207  <var title="">localName</var>, and
  4208  <a href="#concept-node-document" title="concept-node-document">node document</a> set to the
  4209  <a href="#context-object">context object</a>.
  4210 </ol>
  4211 
  4212 <p>The
  4213 <dfn id="dom-document-createdocumentfragment" title="dom-Document-createDocumentFragment"><code>createDocumentFragment()</code></dfn>
  4214 method must return a new <code><a href="#documentfragment">DocumentFragment</a></code>
  4215 <a href="#concept-node" title="concept-node">node</a> with its
  4216 <a href="#concept-node-document" title="concept-node-document">node document</a> set to the
  4217 <a href="#context-object">context object</a>.
  4218 
  4219 <p>The
  4220 <dfn id="dom-document-createtextnode" title="dom-Document-createTextNode"><code>createTextNode(<var title="">data</var>)</code></dfn>
  4221 method must return a new <code><a href="#text">Text</a></code>
  4222 <a href="#concept-node" title="concept-node">node</a> with its
  4223 <a href="#concept-cd-data" title="concept-CD-data">data</a> set to <var title="">data</var> and
  4224 <a href="#concept-node-document" title="concept-node-document">node document</a> set to the
  4225 <a href="#context-object">context object</a>.
  4226 <p class="note">No check is performed that <var title="">data</var> consists of
  4227 characters that match the <code class="external" data-anolis-spec="xml"><a href="http://www.w3.org/TR/xml/#NT-Char">Char</a></code> production.
  4228 
  4229 <p>The
  4230 <dfn id="dom-document-createcomment" title="dom-Document-createComment"><code>createComment(<var title="">data</var>)</code></dfn>
  4231 method must return a new <code><a href="#comment">Comment</a></code>
  4232 <a href="#concept-node" title="concept-node">node</a> with its
  4233 <a href="#concept-cd-data" title="concept-CD-data">data</a> set to <var title="">data</var> and
  4234 <a href="#concept-node-document" title="concept-node-document">node document</a> set to the
  4235 <a href="#context-object">context object</a>.
  4236 <p class="note">No check is performed that <var title="">data</var> consists of
  4237 characters that match the <code class="external" data-anolis-spec="xml"><a href="http://www.w3.org/TR/xml/#NT-Char">Char</a></code> production
  4238 or that it contains two adjacent hyphens or ends with a hyphen.
  4239 
  4240 <p>The <dfn id="dom-document-createprocessinginstruction" title="dom-Document-createProcessingInstruction"><code>createProcessingInstruction(<var title="">target</var>, <var title="">data</var>)</code></dfn> method must run these steps:
  4241 
  4242 <ol>
  4243  <li><p>If <var title="">target</var> does not match the
  4244  <!--<code data-anolis-spec=xml>PITarget</code>-->
  4245  <code class="external" data-anolis-spec="xml"><a href="http://www.w3.org/TR/xml/#NT-Name">Name</a></code> production,
  4246  <a href="#concept-throw" title="concept-throw">throw</a> an
  4247  "<code><a href="#invalidcharactererror">InvalidCharacterError</a></code>" exception and terminate these
  4248  steps. <!-- DOM3 does not check for "xml" -->
  4249 
  4250  <li><p>If <var title="">data</var> contains the string
  4251  "<code title="">?&gt;</code>", <a href="#concept-throw" title="concept-throw">throw</a> an
  4252  "<code><a href="#invalidcharactererror">InvalidCharacterError</a></code>" exception and terminate these
  4253  steps. <!-- Gecko does this. -->
  4254 
  4255  <!--<li><p>If <var title>target</var> contains a U+003A COLON (":")
  4256  character, <span title=concept-throw>throw</span> a
  4257  "<code>NamespaceError</code>" exception and terminate these steps.-->
  4258  <!-- DOM3 didn't check this -->
  4259 
  4260  <li><p>Return a new <code><a href="#processinginstruction">ProcessingInstruction</a></code>
  4261  <a href="#concept-node" title="concept-node">node</a>, with
  4262  <a href="#concept-pi-target" title="concept-PI-target">target</a> set to <var title="">target</var>,
  4263  <a href="#concept-cd-data" title="concept-CD-data">data</a> set to <var title="">data</var>, and
  4264  <a href="#concept-node-document" title="concept-node-document">node document</a> set to the
  4265  <a href="#context-object">context object</a>.
  4266 </ol>
  4267 
  4268 <p class="note">No check is performed that <var title="">target</var> contains
  4269 "<code title="">xml</code>" or "<code title="">:</code>", or that
  4270 <var title="">data</var> contains characters that match the
  4271 <code class="external" data-anolis-spec="xml"><a href="http://www.w3.org/TR/xml/#NT-Char">Char</a></code> production.
  4272 
  4273 <!--
  4274 [createAttribute]
  4275 <p>The <dfn title=dom-Document-createAttribute><code>createAttribute(<var title>name</var>)</code></dfn> method must run these steps:
  4276 <ol>
  4277  <li><p>If <var title>name</var> does not match the <code data-anolis-spec=xml>Name</code> production in XML,
  4278  <span title=concept-throw>throw</span> an
  4279  "<code>InvalidCharacterError</code>"
  4280  exception and terminate these steps.
  4281  <li><p>Return a new <code>Attr</code> node with its <code title=dom-Node-namespaceURI>namespaceURI</code> set to null, <code title=dom-Node-prefix>prefix</code> set to null, <code title=dom-Node-localName>localName</code> set to <var title>name</var>, and <span title=concept-node-document>node document</span> set to the <span>context object</span>.
  4282 </ol>-->
  4283 <!-- this is different from DOM3 -->
  4284 <!--<p class=note>No check is performed that the local name will match the <code
  4285 data-anolis-spec=xmlns>NCName</code> production in Namespaces in XML.-->
  4286 
  4287 <hr>
  4288 
  4289 <dl class="domintro">
  4290  <dt><var title="">clone</var> = <var title="">document</var> . <code title="dom-Document-importNode"><a href="#dom-document-importnode">importNode(<var>node</var> [, <var>deep</var>])</a></code>
  4291  <dd>
  4292  <dd>
  4293   <p>Returns a copy of <var title="">node</var>. If
  4294   <var title="">deep</var> is true or omitted, the copy also includes the
  4295   <var title="">node</var> <a href="#concept-tree-child" title="concept-tree-child">children</a>.
  4296 
  4297   <p>If <var title="">node</var> is a
  4298   <a href="#concept-document" title="concept-document">document</a> throws a
  4299   "<code><a href="#notsupportederror">NotSupportedError</a></code>"
  4300   exception.
  4301 
  4302  <dt><var title="">node</var> = <var title="">document</var> . <code title="dom-Document-adoptNode"><a href="#dom-document-adoptnode">adoptNode(<var>node</var>)</a></code>
  4303 
  4304  <dd>
  4305   <p>Moves <var title="">node</var> from another
  4306   <a href="#concept-document" title="concept-document">document</a> and returns it.
  4307 
  4308   <p>If <var title="">node</var> is a
  4309   <a href="#concept-document" title="concept-document">document</a> throws a
  4310   "<code><a href="#notsupportederror">NotSupportedError</a></code>"
  4311   exception.
  4312 </dl>
  4313 
  4314 <p>The
  4315 <dfn id="dom-document-importnode" title="dom-Document-importNode"><code>importNode(<var title="">node</var>, <var title="">deep</var>)</code></dfn>
  4316 method must run these steps:
  4317 
  4318 <ol>
  4319  <li><p>If <var title="">node</var> is a
  4320  <a href="#concept-document" title="concept-document">document</a>,
  4321  <a href="#concept-throw" title="concept-throw">throw</a> a
  4322  "<code><a href="#notsupportederror">NotSupportedError</a></code>" exception and terminate these steps.
  4323 
  4324  <li><p>Return a <a href="#concept-node-clone" title="concept-node-clone">clone</a> of
  4325  <var title="">node</var>, with <i title="">document</i>
  4326  <a href="#context-object">context object</a> and the <i title="">clone children flag</i> set if
  4327  <var title="">deep</var> is true.
  4328 </ol>
  4329 
  4330 <p>To <dfn id="concept-node-adopt" title="concept-node-adopt">adopt</dfn> a <var title="">node</var>,
  4331 with an <var title="">ownerDocument</var>, run these steps:
  4332 
  4333 <ol>
  4334  <li><p>If <var title="">node</var> is an
  4335  <a href="#concept-element" title="concept-element">element</a>, it is
  4336  <a href="#affected-by-a-base-url-change">affected by a base URL change</a>.
  4337 
  4338  <li><p>If <var title="">node</var>'s
  4339  <a href="#concept-tree-parent" title="concept-tree-parent">parent</a> is not null, <a href="#concept-node-remove" title="concept-node-remove">remove</a>
  4340  <var title="">node</var> from its
  4341  <a href="#concept-tree-parent" title="concept-tree-parent">parent</a>.
  4342 
  4343  <li><p>Set <a href="#concept-node-document" title="concept-node-document">node document</a> for
  4344  <var title="">node</var> and all its
  4345  <a href="#concept-tree-descendant" title="concept-tree-descendant">descendants</a>
  4346  <!--AttrExodus as well as any associated <code>Attr</code> nodes-->
  4347  to <var title="">ownerDocument</var>.
  4348 </ol>
  4349 
  4350 <p>The
  4351 <dfn id="dom-document-adoptnode" title="dom-Document-adoptNode"><code>adoptNode(<var title="">node</var>)</code></dfn>
  4352 method must run these steps:
  4353 
  4354 <ol>
  4355  <li><p>If <var title="">node</var> is a
  4356  <a href="#concept-document" title="concept-document">document</a>,
  4357  <a href="#concept-throw" title="concept-throw">throw</a> a
  4358  "<code><a href="#notsupportederror">NotSupportedError</a></code>" exception and terminate these steps.
  4359 
  4360  <li><p><a href="#concept-node-adopt" title="concept-node-adopt">Adopt</a> <var title="">node</var>
  4361  with the <a href="#context-object">context object</a>.
  4362 
  4363  <li><p>Return <var title="">node</var>.
  4364 </ol>
  4365 
  4366 <hr>
  4367 
  4368 <!-- no "domintro" because better to use constructors -->
  4369 <p>The
  4370 <dfn id="dom-document-createevent" title="dom-Document-createEvent"><code>createEvent(<var title="">interface</var>)</code></dfn>
  4371 method must run these steps:
  4372 
  4373 <ol>
  4374  <li><p>Let <var title="">event</var> be null.
  4375 
  4376  <li>
  4377   <p>If <var title="">interface</var> is an
  4378   <a href="#ascii-case-insensitive">ASCII case-insensitive</a> match for any of the strings in the
  4379   first column in the following table, let <var title="">event</var> be the
  4380   interface in the second column on the same row as the matching string:
  4381 
  4382   <table>
  4383    <thead>
  4384     <tr><th>String<th>Interface
  4385    <tbody>
  4386     <tr><td>"<code title="">event</code>"<td rowspan="3"><code><a href="#event">Event</a></code>
  4387     <tr><td>"<code title="">events</code>"
  4388     <tr><td>"<code title="">htmlevents</code>"
  4389     <tr><td>"<code title="">mouseevent</code>"<td rowspan="2"><code>MouseEvent</code>
  4390     <tr><td>"<code title="">mouseevents</code>"
  4391     <!--
  4392     <tr><td>"<code title>mutationevent</code>"<td rowspan=2><code>MutationEvent</code>
  4393     <tr><td>"<code title>mutationevents</code>"
  4394     -->
  4395     <tr><td>"<code title="">uievent</code>"<td rowspan="2"><code>UIEvent</code>
  4396     <tr><td>"<code title="">uievents</code>"
  4397   </table>
  4398 
  4399  <li>
  4400   <p>If <var title="">event</var> is null or an interface that is not
  4401   supported, <a href="#concept-throw" title="concept-throw">throw</a> a
  4402   "<code><a href="#notsupportederror">NotSupportedError</a></code>" and terminate these steps.
  4403 
  4404   <p class="note">In practice all user agents will support the
  4405   <code>MouseEvent</code> and <code>UIEvent</code> interface, but this
  4406   specification is not going to require that to avoid a needless dependency.
  4407 
  4408  <li><p>Create an <a href="#concept-event" title="concept-event">event</a> implementing the
  4409  <var title="">event</var> interface and return it.
  4410 </ol>
  4411 
  4412 <p class="note">This method is pretty much obsolete as
  4413 <a href="#concept-event" title="concept-event">events</a> have constructors these days, but
  4414 needs to be supported for legacy content. Tough.
  4415 
  4416 <hr>
  4417 
  4418 <dl class="domintro">
  4419  <dt><var title="">event</var> = <var title="">document</var> . <code title="dom-Document-createRange"><a href="#dom-document-createrange">createRange()</a></code>
  4420  <dd><p>Returns a new <a href="#concept-range" title="concept-range">range</a>.
  4421 </dl>
  4422 
  4423 <p>The <dfn id="dom-document-createrange" title="dom-Document-createRange"><code>createRange()</code></dfn>
  4424 method must return a new <a href="#concept-range" title="concept-range">range</a> with
  4425 (<a href="#context-object">context object</a>, 0) as its
  4426 <a href="#concept-range-start" title="concept-range-start">start</a> and
  4427 <a href="#concept-range-end" title="concept-range-end">end</a>.
  4428 
  4429 <hr>
  4430 
  4431 <p>The
  4432 <dfn id="dom-document-createnodeiterator" title="dom-Document-createNodeIterator"><code>createNodeIterator(<var>root</var>, <var>whatToShow</var>, <var>filter</var>)</code></dfn>
  4433 method must run these steps:
  4434 
  4435 <ol>
  4436  <li><p>Create a <code><a href="#nodeiterator">NodeIterator</a></code> object.
  4437  <li><p>Set <a href="#concept-traversal-root" title="concept-traversal-root">root</a> and initialize
  4438  the <code title="dom-NodeIterator-referenceNode"><a href="#dom-nodeiterator-referencenode">referenceNode</a></code>
  4439  attribute to the <var title="">root</var> argument.
  4440  <li><p>Set <a href="#concept-traversal-whattoshow" title="concept-traversal-whatToShow">whatToShow</a> to
  4441  the <var title="">whatToShow</var> argument.
  4442  <li><p>Set <a href="#concept-traversal-filter" title="concept-traversal-filter">filter</a> to
  4443  <var title="">filter</var>.
  4444  <li><p>Return the newly created <code><a href="#nodeiterator">NodeIterator</a></code> object.
  4445 </ol>
  4446 
  4447 <p>The
  4448 <dfn id="dom-document-createtreewalker" title="dom-Document-createTreeWalker"><code>createTreeWalker(<var>root</var>, <var>whatToShow</var>, <var>filter</var>)</code></dfn>
  4449 method must run these steps:
  4450 
  4451 <ol>
  4452  <li><p>Create a <code><a href="#treewalker">TreeWalker</a></code> object.
  4453  <li><p>Set <a href="#concept-traversal-root" title="concept-traversal-root">root</a> and initialize
  4454  the <code title="dom-TreeWalker-currentNode"><a href="#dom-treewalker-currentnode">currentNode</a></code> attribute to
  4455  the <var title="">root</var> argument.
  4456  <li><p>Set <a href="#concept-traversal-whattoshow" title="concept-traversal-whatToShow">whatToShow</a> to
  4457  the <var title="">whatToShow</var> argument.
  4458  <li><p>Set <a href="#concept-traversal-filter" title="concept-traversal-filter">filter</a> to
  4459  <var title="">filter</var>.
  4460  <li><p>Return the newly created <code><a href="#treewalker">TreeWalker</a></code> object.
  4461 </ol>
  4462 
  4463 
  4464 
  4465 <h4 id="interface-domimplementation"><span class="secno">5.5.1 </span>Interface <code><a href="#domimplementation">DOMImplementation</a></code></h4>
  4466 <p>User agents must create a <code><a href="#domimplementation">DOMImplementation</a></code> object whenever
  4467 a <a href="#concept-document" title="concept-document">document</a> is created and associate it
  4468 with that <a href="#concept-document" title="concept-document">document</a>.
  4469 
  4470 <pre class="idl">interface <dfn id="domimplementation">DOMImplementation</dfn> {
  4471   <a href="#documenttype">DocumentType</a> <a href="#dom-domimplementation-createdocumenttype" title="dom-DOMImplementation-createDocumentType">createDocumentType</a>(DOMString qualifiedName, DOMString publicId, DOMString systemId);
  4472   <a href="#xmldocument">XMLDocument</a> <a href="#dom-domimplementation-createdocument" title="dom-DOMImplementation-createDocument">createDocument</a>(DOMString? <var title="">namespace</var>, [TreatNullAs=EmptyString] DOMString <var title="">qualifiedName</var>, <a href="#documenttype">DocumentType</a>? <var title="">doctype</var>);
  4473   <a href="#document">Document</a> <a href="#dom-domimplementation-createhtmldocument" title="dom-DOMImplementation-createHTMLDocument">createHTMLDocument</a>(optional DOMString <var title="">title</var>);
  4474 
  4475   boolean <a href="#dom-domimplementation-hasfeature" title="dom-DOMImplementation-hasFeature">hasFeature</a>(DOMString feature, [TreatNullAs=EmptyString] DOMString version);
  4476 };</pre>
  4477 
  4478 <dl class="domintro">
  4479  <dt><var title="">doctype</var> = <var title="">document</var> . <code title="dom-Document-implementation"><a href="#dom-document-implementation">implementation</a></code> . <code title="dom-DOMImplementation-createDocumentType"><a href="#dom-domimplementation-createdocumenttype">createDocumentType</a></code>(
  4480  <var title="">qualifiedName</var>, <var title="">publicId</var>, <var title="">systemId</var> )
  4481 
  4482  <dd>
  4483   <p>Returns a <a href="#concept-doctype" title="concept-doctype">doctype</a>, with the given
  4484   <var title="">qualifiedName</var>, <var title="">publicId</var>, and
  4485   <var title="">systemId</var>. If <var title="">qualifiedName</var> does not
  4486   match the <code class="external" data-anolis-spec="xml"><a href="http://www.w3.org/TR/xml/#NT-Name">Name</a></code> production, an
  4487   "<code><a href="#invalidcharactererror">InvalidCharacterError</a></code>"
  4488   exception is thrown, and if it does not match the
  4489   <code class="external" data-anolis-spec="xmlns"><a href="http://www.w3.org/TR/xml-names/#NT-QName">QName</a></code> production, a
  4490   "<code><a href="#namespaceerror">NamespaceError</a></code>" exception
  4491   is thrown.
  4492 
  4493 
  4494  <dt><var title="">doc</var> = <var title="">document</var> . <code title="dom-Document-implementation"><a href="#dom-document-implementation">implementation</a></code> . <code title="dom-DOMImplementation-createDocument"><a href="#dom-domimplementation-createdocument">createDocument</a></code>( <var title="">namespace</var>, <var title="">qualifiedName</var>, <var title="">doctype</var> )
  4495 
  4496  <dd>
  4497   <p>Returns an <code><a href="#xmldocument">XMLDocument</a></code>, with a
  4498   <a href="#document-element">document element</a> whose
  4499   <a href="#concept-element-local-name" title="concept-element-local-name">local name</a> is
  4500   <var title="">qualifiedName</var> and whose
  4501   <a href="#concept-element-namespace" title="concept-element-namespace">namespace</a> is
  4502   <var title="">namespace</var> (unless <var title="">qualifiedName</var> is the
  4503   empty string), and with <var title="">doctype</var>, if it is given, as its
  4504   <a href="#concept-doctype" title="concept-doctype">doctype</a>.
  4505 
  4506   <p>This method throws the same exceptions as the <code title="dom-Document-createElementNS"><a href="#dom-document-createelementns">createElementNS</a></code> method, when
  4507   invoked with the same arguments.
  4508 
  4509 
  4510  <dt><code><var title="">doc</var> = <var title="">document</var> . <a href="#dom-document-implementation" title="dom-Document-implementation">implementation</a> . <a href="#dom-domimplementation-createhtmldocument" title="dom-DOMImplementation-createHTMLDocument">createHTMLDocument</a>([<var title="">title</var>])</code>
  4511 
  4512  <dd>
  4513   <p>Returns a <a href="#concept-document" title="concept-document">document</a>, with a basic
  4514   <a href="#concept-tree" title="concept-tree">tree</a> already constructed including a
  4515   <code title="">title</code> element, unless the <var title="">title</var>
  4516   argument is omitted.
  4517 
  4518  <dt><code><var title="">document</var> .
  4519  <a href="#dom-document-implementation" title="dom-Document-implementation">implementation</a> .
  4520  <a href="#dom-domimplementation-hasfeature" title="dom-DOMImplementation-hasFeature">hasFeature</a>(
  4521  <var title="">feature</var>, <var title="">version</var>)</code>
  4522 
  4523  <dd>
  4524   <p>If <var title="">feature</var> is an
  4525   <a href="http://www.w3.org/TR/SVG/feature.html">SVG feature</a> string,
  4526   returns whether that feature is supported.  If <var title="">feature</var> is
  4527   not the empty string, only returns true if the feature is supported as
  4528   defined in the given version of the SVG specification (e.g.,
  4529   "<code title="">1.1</code>").
  4530 
  4531   <p>If <var title="">feature</var> is not an SVG feature, but rather some other
  4532   string like "<code title="">HTML</code>" or
  4533   "<code title="">flibbertigibbet</code>", always returns true.  Thus, this method
  4534   is only useful for testing SVG features.
  4535 </dl>
  4536 
  4537 <div class="impl">
  4538 
  4539 <p>The
  4540 <dfn id="dom-domimplementation-createdocumenttype" title="dom-DOMImplementation-createDocumentType"><code>createDocumentType(<var>qualifiedName</var>, <var>publicId</var>, <var>systemId</var>)</code></dfn>
  4541 method must run these steps:
  4542 
  4543 <ol>
  4544  <li><p>If <var title="">qualifiedName</var> does not match the
  4545  <code class="external" data-anolis-spec="xml"><a href="http://www.w3.org/TR/xml/#NT-Name">Name</a></code> production,
  4546  <a href="#concept-throw" title="concept-throw">throw</a> an
  4547  "<code><a href="#invalidcharactererror">InvalidCharacterError</a></code>" exception and terminate these
  4548  steps.
  4549  <li><p>If <var title="">qualifiedName</var> does not match the <code class="external" data-anolis-spec="xmlns"><a href="http://www.w3.org/TR/xml-names/#NT-QName">QName</a></code> production in,
  4550  <a href="#concept-throw" title="concept-throw">throw</a> a
  4551  "<code><a href="#namespaceerror">NamespaceError</a></code>" exception and terminate these steps.
  4552  <!--<li><p>If <var title>publicId</var> contains a character that does not
  4553  match the <code data-anolis-spec=xml>PubidChar</code> production in XML,
  4554  <span title=concept-throw>throw</span> an
  4555  "<code>InvalidCharacterError</code>"
  4556  exception and terminate these steps. --> <!-- DOM3 didn't check this -->
  4557  <!--<li><p>If <var title>systemId</var> contains both a U+0022 QUOTATION MARK ('"') and a U+0027 APOSTROPHE ("'") character,
  4558  <span title=concept-throw>throw</span> an
  4559  "<code>InvalidCharacterError</code>"
  4560  exception and terminate these steps.--> <!-- DOM3 didn't check this -->
  4561  <li><p>Return a new <a href="#concept-doctype" title="concept-doctype">doctype</a>, with
  4562  <var title="">qualifiedName</var> as its
  4563  <a href="#concept-doctype-name" title="concept-doctype-name">name</a>, <var title="">publicId</var> as
  4564  its <a href="#concept-doctype-publicid" title="concept-doctype-publicid">public ID</a>, and
  4565  <var title="">systemId</var> as its
  4566  <a href="#concept-doctype-systemid" title="concept-doctype-systemid">system ID</a>, and with its
  4567  <a href="#concept-node-document" title="concept-node-document">node document</a> set to the
  4568  associated <a href="#concept-document" title="concept-document">document</a> of the
  4569  <a href="#context-object">context object</a>.
  4570 </ol>
  4571 <p class="note">No check is performed that the <var title="">publicId</var>
  4572 matches the <code title="">PublicChar</code> or that the
  4573 <var title="">systemId</var> does not contain both a '<code title="">"</code>' and
  4574 "<code title="">'</code>".
  4575 
  4576 <p>The
  4577 <dfn id="dom-domimplementation-createdocument" title="dom-DOMImplementation-createDocument"><code>createDocument(<var>namespace</var>, <var>qualifiedName</var>, <var>doctype</var>)</code></dfn>
  4578 method must run these steps:
  4579 
  4580 <ol>
  4581  <li>
  4582   <p>Let <var title="">document</var> be a new <code><a href="#xmldocument">XMLDocument</a></code>.
  4583 
  4584   <p class="note">This method creates an <code><a href="#xmldocument">XMLDocument</a></code> rather than
  4585   a normal <a href="#concept-document" title="concept-document">document</a>. They are identical
  4586   except for the addition of the
  4587   <code class="external" data-anolis-spec="html" title="dom-XMLDocument-load"><a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/dom.html#dom-xmldocument-load">load()</a></code>
  4588   method deployed content relies upon.
  4589   <a class="informative" href="#refsHTML">[HTML]</a>
  4590 
  4591  <li><p>Let <var title="">element</var> be null.
  4592 
  4593  <li><p>If <var title="">qualifiedName</var> is not the empty string, set
  4594  <var title="">element</var> to the result of invoking the
  4595  <code title="dom-Document-createElementNS"><a href="#dom-document-createelementns">createElementNS()</a></code> method
  4596  with the arguments <var title="">namespace</var> and
  4597  <var title="">qualifiedName</var> on <var title="">document</var>. If that threw
  4598  an exception, re-throw the exception and terminate these steps.
  4599 
  4600  <li><p>If <var title="">doctype</var> is not null,
  4601  <a href="#concept-node-append" title="concept-node-append">append</a>
  4602  <var title="">doctype</var> to <var title="">document</var>.
  4603 
  4604  <li><p>If <var title="">element</var> is not null,
  4605  <a href="#concept-node-append" title="concept-node-append">append</a>
  4606  <var title="">element</var> to <var title="">document</var>.
  4607 
  4608  <li><p>Return <var title="">document</var>.
  4609 </ol>
  4610 
  4611 <p>The
  4612 <dfn id="dom-domimplementation-createhtmldocument" title="dom-DOMImplementation-createHTMLDocument"><code>createHTMLDocument(<var>title</var>)</code></dfn>
  4613 method must run these steps:
  4614 
  4615 <ol>
  4616  <li><p>Let <var title="">doc</var> be a newly created
  4617  <a href="#concept-document" title="concept-document">document</a>.
  4618 
  4619  <li><p>Mark <var title="">doc</var> as being an <a href="#html-document">HTML document</a>.
  4620 
  4621  <li><p>Set <var title="">doc</var>'s
  4622  <a href="#concept-document-content-type" title="concept-document-content-type">content type</a> to
  4623  "<code title="">text/html</code>".
  4624 
  4625  <li><p>Create a <a href="#concept-doctype" title="concept-doctype">doctype</a>, with
  4626  "<code title="">html</code>"
  4627  as its <a href="#concept-doctype-name" title="concept-doctype-name">name</a> and with its
  4628  <a href="#concept-node-document" title="concept-node-document">node document</a> set to
  4629  <var title="">doc</var>. <a href="#concept-node-append" title="concept-node-append">Append</a>
  4630  the newly created node to <var title="">doc</var>.
  4631 
  4632  <li><p>Create an <code title="">html</code> element in the <a href="#html-namespace">HTML
  4633  namespace</a>, and <a href="#concept-node-append" title="concept-node-append">append</a>
  4634  it to <var title="">doc</var>.
  4635 
  4636  <li><p>Create a <code title="">head</code> element in the <a href="#html-namespace">HTML
  4637  namespace</a>, and  <a href="#concept-node-append" title="concept-node-append">append</a>
  4638  it to the <code title="">html</code> element created in the previous step.
  4639 
  4640  <li>
  4641   <p>If the <var title="">title</var> argument is not omitted:
  4642 
  4643   <ol>
  4644    <li><p>Create a <code title="">title</code> element in the
  4645    <a href="#html-namespace">HTML namespace</a>, and
  4646    <a href="#concept-node-append" title="concept-node-append">append</a> it to the
  4647    <code title="">head</code> element created in the previous step.
  4648 
  4649    <li><p>Create a <code><a href="#text">Text</a></code> <a href="#concept-node" title="concept-node">node</a>,
  4650    set its <a href="#concept-cd-data" title="concept-CD-data">data</a> to <var title="">title</var>
  4651    (which could be the empty string), and
  4652    <a href="#concept-node-append" title="concept-node-append">append</a> it to the
  4653    <code title="">title</code> element created in the previous step.
  4654   </ol>
  4655 
  4656  <li><p>Create a <code title="">body</code> element in the
  4657  <a href="#html-namespace">HTML namespace</a>, and
  4658  <a href="#concept-node-append" title="concept-node-append">append</a> it to the
  4659  <code title="">html</code> element created in the earlier step.
  4660 
  4661  <li><p>Return <var title="">doc</var>.
  4662 </ol>
  4663 
  4664 <p>The <dfn id="dom-domimplementation-hasfeature" title="dom-DOMImplementation-hasFeature"><code>hasFeature(<var title="">feature</var>, <var title="">version</var>)</code></dfn> method must run
  4665 these steps:
  4666 
  4667 <ol>
  4668  <li><p>If <var title="">feature</var> begins with an
  4669  <a href="#ascii-case-insensitive">ASCII case-insensitive</a> match for one of the strings
  4670  "<code title="">http://www.w3.org/TR/SVG</code>",
  4671  "<code title="">org.w3c.dom.svg</code>", or "<code title="">org.w3c.svg</code>":
  4672 
  4673  <ol>
  4674   <li><p>If <var title="">version</var> is the empty string:
  4675 
  4676   <ol>
  4677    <li><p>Return true if there is some SVG specification that defines a feature
  4678    that is an <a href="#ascii-case-insensitive">ASCII case-insensitive</a> match for
  4679    <var title="">feature</var>, and the user agent meets all the requirements of
  4680    that specification for that feature.  Otherwise, return false.
  4681   </ol>
  4682 
  4683   <li><p>Return true if <var title="">version</var> is the version identifier for
  4684   a known SVG specification, and that specification defines a feature that is
  4685   an <a href="#ascii-case-insensitive">ASCII case-insensitive</a> match for <var title="">feature</var>,
  4686   and the user agent meets all the requirements of that specification for that
  4687   feature.  Otherwise, return false.
  4688 
  4689   <p class="XXX">What happens if a feature is only defined in 1.1 but the version
  4690   string passed is 1.0?  Most UAs return true in this case too, but do we want
  4691   to spec that?
  4692  </ol>
  4693 
  4694  <li><p>Return true.
  4695 </ol>
  4696 
  4697 <p class="note"><code title="dom-DOMImplementation-hasFeature"><a href="#dom-domimplementation-hasfeature">hasFeature()</a></code>
  4698 originally would report whether the user agent claimed to support a given DOM
  4699 feature, but experience proved it was not nearly as reliable or granular as
  4700 simply checking whether the desired interfaces, attributes, or methods existed.
  4701 As such, it should no longer be used, but continues to exist (and simply
  4702 returns true) so that old pages don't stop working.  SVG features are a
  4703 separate mechanism that reused the existing method, so they continue to work as
  4704 a special case.
  4705 
  4706 </div>
  4707 
  4708 
  4709 <h3 id="interface-documentfragment"><span class="secno">5.6 </span>Interface <code><a href="#documentfragment">DocumentFragment</a></code></h3>
  4710 <pre class="idl">interface <dfn id="documentfragment">DocumentFragment</dfn> : <a href="#node">Node</a> {
  4711   // NEW
  4712   void <a href="#dom-rootnode-prepend" title="dom-RootNode-prepend">prepend</a>((<a href="#node">Node</a> or DOMString)... <var title="">nodes</var>);
  4713   void <a href="#dom-rootnode-append" title="dom-RootNode-append">append</a>((<a href="#node">Node</a> or DOMString)... <var title="">nodes</var>);
  4714 };</pre>
  4715 
  4716 
  4717 
  4718 <h3 id="interface-documenttype"><span class="secno">5.7 </span>Interface <code><a href="#documenttype">DocumentType</a></code></h3>
  4719 <pre class="idl">interface <dfn id="documenttype">DocumentType</dfn> : <a href="#node">Node</a> {
  4720   readonly attribute DOMString <a href="#dom-documenttype-name" title="dom-DocumentType-name">name</a>;
  4721   readonly attribute DOMString <a href="#dom-documenttype-publicid" title="dom-DocumentType-publicId">publicId</a>;
  4722   readonly attribute DOMString <a href="#dom-documenttype-systemid" title="dom-DocumentType-systemId">systemId</a>;<!--
  4723   readonly attribute DOMString internalSubset;-->
  4724 
  4725   // NEW
  4726   void <a href="#dom-childnode-before" title="dom-ChildNode-before">before</a>((<a href="#node">Node</a> or DOMString)... <var title="">nodes</var>);
  4727   void <a href="#dom-childnode-after" title="dom-ChildNode-after">after</a>((<a href="#node">Node</a> or DOMString)... <var title="">nodes</var>);
  4728   void <a href="#dom-childnode-replace" title="dom-ChildNode-replace">replace</a>((<a href="#node">Node</a> or DOMString)... <var title="">nodes</var>);
  4729   void <a href="#dom-childnode-remove" title="dom-ChildNode-remove">remove</a>();
  4730 };</pre>
  4731 
  4732 <p><code><a href="#documenttype">DocumentType</a></code> <a href="#concept-node" title="concept-node">nodes</a> are
  4733 simply known as <dfn id="concept-doctype" title="concept-doctype">doctypes</dfn>.
  4734 
  4735 <p><a href="#concept-doctype" title="concept-doctype">Doctypes</a> have an associated
  4736 <dfn id="concept-doctype-name" title="concept-doctype-name">name</dfn>,
  4737 <dfn id="concept-doctype-publicid" title="concept-doctype-publicid">public ID</dfn>, and
  4738 <dfn id="concept-doctype-systemid" title="concept-doctype-systemid">system ID</dfn>.
  4739 
  4740 <p>When a <a href="#concept-doctype" title="concept-doctype">doctype</a> is created, its
  4741 <a href="#concept-doctype-name" title="concept-doctype-name">name</a> is always given. Unless
  4742 explicitly given when a <a href="#concept-doctype" title="concept-doctype">doctype</a> is
  4743 created, its <a href="#concept-doctype-publicid" title="concept-doctype-publicid">public ID</a> and
  4744 <a href="#concept-doctype-systemid" title="concept-doctype-systemid">system ID</a> are the empty string.
  4745 
  4746 <p>The <dfn id="dom-documenttype-name" title="dom-DocumentType-name"><code>name</code></dfn> attribute
  4747 must return the <a href="#concept-doctype-name" title="concept-doctype-name">name</a>.
  4748 
  4749 <p>The <dfn id="dom-documenttype-publicid" title="dom-DocumentType-publicId"><code>publicId</code></dfn>
  4750 attribute must return the
  4751 <a href="#concept-doctype-publicid" title="concept-doctype-publicid">public ID</a>.
  4752 
  4753 <p>The <dfn id="dom-documenttype-systemid" title="dom-DocumentType-systemId"><code>systemId</code></dfn>
  4754 attribute must return the
  4755 <a href="#concept-doctype-systemid" title="concept-doctype-systemid">system ID</a>.
  4756 
  4757 
  4758 
  4759 <!-- AttrExodus
  4760 <h3>Interface <code>Attr</code></h3>
  4761 
  4762 <p>The tentative plan is to let <code>Attr</code> no longer have
  4763 child nodes and turn it into a very lightweight object that no longer
  4764 inherits from <code>Node</code> &mdash;
  4765 <a href=http://lists.w3.org/Archives/Public/public-webapps/2010JulSep/0797.html>http://lists.w3.org/Archives/Public/public-webapps/2010JulSep/0797.html</a>
  4766 
  4767 <pre class=idl>interface <dfn>Attr</dfn> : <span>Node</span> {
  4768   readonly attribute DOMString <span title=dom-Attr-name>name</span>;
  4769   readonly attribute boolean <span title=dom-Attr-specified>specified</span>;
  4770            attribute DOMString <span title=dom-Attr-value>value</span>;
  4771   readonly attribute <span>Element</span> <span title=dom-Attr-ownerElement>ownerElement</span>;<!- -
  4772   readonly attribute boolean isId;- ->
  4773 };</pre>
  4774 
  4775 <p><code>Attr</code> nodes represent <dfn
  4776 title=concept-attribute>attributes</dfn>. They have a <dfn
  4777 title=concept-attribute-name>name</dfn> and an <dfn
  4778 title=concept-attribute-element>element</dfn> associated with them when they are
  4779 created<!- -, or when they are passed as the argument to the <code
  4780 title=dom-Element-setAttributeNode>setAttributeNode</code> method.
  4781 [createAttribute]- ->. <code>Attr</code> nodes are not considered part of the
  4782 document tree, so their <code title=dom-Node-parentNode>parentNode</code>, <code
  4783 title=dom-Node-previousSibling>previousSibling</code> and <code
  4784 title=dom-Node-nextSibling>nextSibling</code> attributes return null. Also, its
  4785 child nodes can not be manipulated directly through the <code
  4786 title=dom-Node-insertBefore>insertBefore</code>, <code
  4787 title=dom-Node-replaceChild>replaceChild</code> and <code
  4788 title=dom-Node-appendChild>appendChild</code> methods.
  4789 
  4790 <p>The <dfn title=dom-Attr-name><code>name</code></dfn> attribute must return
  4791 the <span title=concept-attribute-name>name</span> associated with the
  4792 <span>context object</span>.
  4793 
  4794 <p>The <dfn title=dom-Attr-specified><code>specified</code></dfn> attribute must
  4795 return true.
  4796 
  4797 <p>The <dfn title=dom-Attr-value><code>value</code></dfn> attribute must return the value of the <span>context object</span>'s
  4798 <code title=dom-Node-textContent>textContent</code> attribute and on
  4799 setting, must set the <span>context object</span>'s
  4800 <code title=dom-Node-textContent>textContent</code> attribute to the new
  4801 value.
  4802 
  4803 <p>The <dfn title=dom-Attr-ownerElement><code>ownerElement</code></dfn>
  4804 attribute must return the <span title=concept-attribute-element>element</span>
  4805 associated with the <span>context object</span><!- -, if there is one, or null
  4806 otherwise [createAttribute]- ->.
  4807 -->
  4808 
  4809 
  4810 <h3 id="interface-element"><span class="secno">5.8 </span>Interface <code><a href="#element">Element</a></code></h3>
  4811 <pre class="idl">interface <dfn id="element">Element</dfn> : <a href="#node">Node</a> {
  4812   readonly attribute DOMString? <a href="#dom-element-namespaceuri" title="dom-Element-namespaceURI">namespaceURI</a>;
  4813   readonly attribute DOMString? <a href="#dom-element-prefix" title="dom-Element-prefix">prefix</a>;
  4814   readonly attribute DOMString <a href="#dom-element-localname" title="dom-Element-localName">localName</a>;
  4815   readonly attribute DOMString <a href="#dom-element-tagname" title="dom-Element-tagName">tagName</a>;
  4816 
  4817            attribute DOMString <a href="#dom-element-id" title="dom-Element-id">id</a>;
  4818            attribute DOMString <a href="#dom-element-classname" title="dom-Element-className">className</a>;
  4819   readonly attribute <a href="#domtokenlist">DOMTokenList</a> <a href="#dom-element-classlist" title="dom-Element-classList">classList</a>;
  4820 
  4821   readonly attribute <a href="#attr">Attr</a>[] <a href="#dom-element-attributes" title="dom-Element-attributes">attributes</a>;
  4822   DOMString? <a href="#dom-element-getattribute" title="dom-Element-getAttribute">getAttribute</a>(DOMString <var title="">name</var>);
  4823   DOMString? <a href="#dom-element-getattributens" title="dom-Element-getAttributeNS">getAttributeNS</a>(DOMString? <var title="">namespace</var>, DOMString <var title="">localName</var>);
  4824   void <a href="#dom-element-setattribute" title="dom-Element-setAttribute">setAttribute</a>(DOMString <var title="">name</var>, DOMString <var title="">value</var>);
  4825   void <a href="#dom-element-setattributens" title="dom-Element-setAttributeNS">setAttributeNS</a>(DOMString? <var title="">namespace</var>, DOMString <var title="">name</var>, DOMString <var title="">value</var>);
  4826   void <a href="#dom-element-removeattribute" title="dom-Element-removeAttribute">removeAttribute</a>(DOMString <var title="">name</var>);
  4827   void <a href="#dom-element-removeattributens" title="dom-Element-removeAttributeNS">removeAttributeNS</a>(DOMString? <var title="">namespace</var>, DOMString <var title="">localName</var>);
  4828   boolean <a href="#dom-element-hasattribute" title="dom-Element-hasAttribute">hasAttribute</a>(DOMString <var title="">name</var>);
  4829   boolean <a href="#dom-element-hasattributens" title="dom-Element-hasAttributeNS">hasAttributeNS</a>(DOMString? <var title="">namespace</var>, DOMString <var title="">localName</var>);
  4830 <!--
  4831   <span>Attr</span> <span title=dom-Element-getAttributeNode>getAttributeNode</span>(DOMString name);
  4832   <span>Attr</span> <span title=dom-Element-getAttributeNodeNS>getAttributeNodeNS</span>(DOMString namespace, DOMString localName);
  4833   <span>Attr</span> <span title=dom-Element-setAttributeNode>setAttributeNode</span>(Attr newAttr);
  4834   <span>Attr</span> <span title=dom-Element-removeAttributeNode>removeAttributeNode</span>(Attr oldAttr);
  4835 -->
  4836   <a href="#htmlcollection">HTMLCollection</a> <a href="#dom-element-getelementsbytagname" title="dom-Element-getElementsByTagName">getElementsByTagName</a>(DOMString <var title="">localName</var>);
  4837   <a href="#htmlcollection">HTMLCollection</a> <a href="#dom-element-getelementsbytagnamens" title="dom-Element-getElementsByTagNameNS">getElementsByTagNameNS</a>(DOMString? <var title="">namespace</var>, DOMString <var title="">localName</var>);
  4838   <a href="#htmlcollection">HTMLCollection</a> <a href="#dom-element-getelementsbyclassname" title="dom-Element-getElementsByClassName">getElementsByClassName</a>(DOMString <var title="">classNames</var>);
  4839 
  4840   readonly attribute <a href="#htmlcollection">HTMLCollection</a> <a href="#dom-element-children" title="dom-Element-children">children</a>;
  4841   readonly attribute <a href="#element">Element</a>? <a href="#dom-element-firstelementchild" title="dom-Element-firstElementChild">firstElementChild</a>;
  4842   readonly attribute <a href="#element">Element</a>? <a href="#dom-element-lastelementchild" title="dom-Element-lastElementChild">lastElementChild</a>;
  4843   readonly attribute <a href="#element">Element</a>? <a href="#dom-element-previouselementsibling" title="dom-Element-previousElementSibling">previousElementSibling</a>;
  4844   readonly attribute <a href="#element">Element</a>? <a href="#dom-element-nextelementsibling" title="dom-Element-nextElementSibling">nextElementSibling</a>;
  4845   readonly attribute unsigned long <a href="#dom-element-childelementcount" title="dom-Element-childElementCount">childElementCount</a>;<!-- XXX remove??-->
  4846 
  4847   // NEW
  4848   void <a href="#dom-rootnode-prepend" title="dom-RootNode-prepend">prepend</a>((<a href="#node">Node</a> or DOMString)... <var title="">nodes</var>);
  4849   void <a href="#dom-rootnode-append" title="dom-RootNode-append">append</a>((<a href="#node">Node</a> or DOMString)... <var title="">nodes</var>);
  4850   void <a href="#dom-childnode-before" title="dom-ChildNode-before">before</a>((<a href="#node">Node</a> or DOMString)... <var title="">nodes</var>);
  4851   void <a href="#dom-childnode-after" title="dom-ChildNode-after">after</a>((<a href="#node">Node</a> or DOMString)... <var title="">nodes</var>);
  4852   void <a href="#dom-childnode-replace" title="dom-ChildNode-replace">replace</a>((<a href="#node">Node</a> or DOMString)... <var title="">nodes</var>);
  4853   void <a href="#dom-childnode-remove" title="dom-ChildNode-remove">remove</a>();
  4854 };</pre>
  4855 
  4856 <p><code><a href="#element">Element</a></code> <a href="#concept-node" title="concept-node">nodes</a> are simply
  4857 known as <dfn id="concept-element" title="concept-element">elements</dfn>.</p>
  4858 
  4859 <p><a href="#concept-element" title="concept-element">Elements</a> have an associated
  4860 <dfn id="concept-element-namespace" title="concept-element-namespace">namespace</dfn>,
  4861 <dfn id="concept-element-namespace-prefix" title="concept-element-namespace-prefix">namespace prefix</dfn>, and
  4862 <dfn id="concept-element-local-name" title="concept-element-local-name">local name</dfn>. When an
  4863 <a href="#concept-element" title="concept-element">element</a> is created, its
  4864 <a href="#concept-element-local-name" title="concept-element-local-name">local name</a> is always given.
  4865 Unless explicitly given when an <a href="#concept-element" title="concept-element">element</a>
  4866 is created, its <a href="#concept-element-namespace" title="concept-element-namespace">namespace</a> and
  4867 <a href="#concept-element-namespace-prefix" title="concept-element-namespace-prefix">namespace prefix</a> are
  4868 null.
  4869 
  4870 <p><a href="#concept-element" title="concept-element">Elements</a> also have an ordered
  4871 <dfn id="concept-element-attribute" title="concept-element-attribute">attribute list</dfn>. Unless
  4872 explicitly given when an <a href="#concept-element" title="concept-element">element</a> is
  4873 created, its
  4874 <a href="#concept-element-attribute" title="concept-element-attribute">attribute list</a> is empty. An
  4875 <a href="#concept-element" title="concept-element">element</a>
  4876 <dfn id="concept-element-attribute-has" title="concept-element-attribute-has">has</dfn> an
  4877 <a href="#concept-attribute" title="concept-attribute">attribute</a> <var title="">A</var> if
  4878 <var title="">A</var> is in its
  4879 <a href="#concept-element-attribute" title="concept-element-attribute">attribute list</a>.
  4880 
  4881 <p><a href="#concept-element" title="concept-element">Elements</a> can have a
  4882 <dfn id="concept-id" title="concept-id">unique identifier (ID)</dfn> and
  4883 <dfn id="concept-class" title="concept-class">classes</dfn> associated with them.
  4884 
  4885 <p class="note">Historically <a href="#concept-element" title="concept-element">elements</a> could
  4886 have multiple identifiers e.g. by using the HTML <code title="">id</code>
  4887 <a href="#concept-attribute" title="concept-attribute">attribute</a> and a DTD. This specification
  4888 makes <a href="#concept-id" title="concept-id">ID</a> a concept of the DOM and allows for
  4889 only one per <a href="#concept-element" title="concept-element">element</a>, given by an
  4890 <code title="">id</code> <a href="#concept-attribute" title="concept-attribute">attribute</a>.
  4891 
  4892 <p>An <a href="#concept-element" title="concept-element">element</a> has an
  4893 <a href="#concept-id" title="concept-id">ID</a> if it
  4894 <a href="#concept-element-attribute-has" title="concept-element-attribute-has">has</a> an
  4895 <a href="#concept-named-attribute" title="concept-named-attribute"><code>id</code> attribute</a> whose
  4896 <a href="#concept-attribute-value" title="concept-attribute-value">value</a> is not the empty string.
  4897 The <a href="#concept-id" title="concept-id">ID</a> is that
  4898 <a href="#concept-attribute" title="concept-attribute">attribute</a>'s
  4899 <a href="#concept-attribute-value" title="concept-attribute-value">value</a>.
  4900 
  4901 <p>An <a href="#concept-element" title="concept-element">element</a> has
  4902 <a href="#concept-class" title="concept-class">classes</a> if it
  4903 <a href="#concept-element-attribute-has" title="concept-element-attribute-has">has</a> a
  4904 <a href="#concept-named-attribute" title="concept-named-attribute"><code>class</code> attribute</a>, and
  4905 <a href="#split-a-string-on-spaces" title="split a string on spaces">splitting</a> that
  4906 <a href="#concept-attribute" title="concept-attribute">attribute</a>'s
  4907 <a href="#concept-attribute-value" title="concept-attribute-value">value</a> does not return an empty
  4908 list. The <a href="#concept-class" title="concept-class">classes</a> are that
  4909 <a href="#concept-attribute" title="concept-attribute">attribute</a>'s
  4910 <a href="#concept-attribute-value" title="concept-attribute-value">value</a>
  4911 <a href="#split-a-string-on-spaces" title="split a string on spaces">split on spaces</a>.
  4912 
  4913 <p class="note">While this specification defines user agent processing
  4914 requirements for <code title="">id</code> and <code title="">class</code>
  4915 <a href="#concept-attribute" title="concept-attribute">attributes</a> on any
  4916 <a href="#concept-element" title="concept-element">element</a>, it makes no claims as to whether
  4917 using them is conforming or not.
  4918 
  4919 <hr>
  4920 
  4921 <p>A <a href="#concept-node" title="concept-node">node</a>'s
  4922 <a href="#concept-tree-parent" title="concept-tree-parent">parent</a> of type
  4923 <code><a href="#element">Element</a></code> is known as a <dfn id="parent-element">parent element</dfn>. If the
  4924 <a href="#concept-node" title="concept-node">node</a> has a
  4925 <a href="#concept-tree-parent" title="concept-tree-parent">parent</a> of a different type, its
  4926 <a href="#parent-element">parent element</a> is null.</p>
  4927 
  4928 <p>The <dfn id="document-element">document element</dfn> of a
  4929 <a href="#concept-document" title="concept-document">document</a> is the
  4930 <a href="#concept-element" title="concept-element">element</a> whose
  4931 <a href="#concept-tree-parent" title="concept-tree-parent">parent</a> is that
  4932 <a href="#concept-document" title="concept-document">document</a>, if it exists, and null otherwise.
  4933 
  4934 <p class="note">As explained in the <a href="#node-tree">node tree</a> section,
  4935 there can only be one such <a href="#concept-element" title="concept-element">element</a>.
  4936 
  4937 <p>When an <a href="#concept-element" title="concept-element">element</a> or one of its
  4938 <a href="#concept-tree-ancestor" title="concept-tree-ancestor">ancestors</a> is the
  4939 <a href="#document-element">document element</a>, it is <dfn id="in-a-document">in a document</dfn>.
  4940 
  4941 <hr>
  4942 
  4943 <p>Specifications may define <dfn id="base-url-change-steps">base URL change steps</dfn>.
  4944 
  4945 <p>When an <a href="#concept-element" title="concept-element">element</a> is
  4946 <dfn id="affected-by-a-base-url-change">affected by a base URL change</dfn>, the user agent must run the
  4947 <a href="#base-url-change-steps">base URL change steps</a>, as defined in
  4948 <a href="#other-applicable-specifications">other applicable specifications</a>.
  4949 
  4950 <hr>
  4951 
  4952 <dl class="domintro">
  4953  <dt><var title="">namespace</var> = <var title="">element</var> . <code title="dom-Element-namespaceURI"><a href="#dom-element-namespaceuri">namespaceURI</a></code>
  4954  <dd><p>Returns the <a href="#concept-element-namespace" title="concept-element-namespace">namespace</a>.
  4955 
  4956  <dt><var title="">prefix</var> = <var title="">element</var> . <code title="dom-Element-prefix"><a href="#dom-element-prefix">prefix</a></code>
  4957  <dd><p>Returns the
  4958  <a href="#concept-element-namespace-prefix" title="concept-element-namespace-prefix">namespace prefix</a>.
  4959 
  4960  <dt><var title="">localName</var> = <var title="">element</var> . <code title="dom-Element-localName"><a href="#dom-element-localname">localName</a></code>
  4961  <dd><p>Returns the
  4962  <a href="#concept-element-local-name" title="concept-element-local-name">local name</a>.
  4963 
  4964  <dt><var title="">qualifiedName</var> = <var title="">element</var> . <code title="dom-Element-tagName"><a href="#dom-element-tagname">tagName</a></code>
  4965  <dd><p>If
  4966  <a href="#concept-element-namespace-prefix" title="concept-element-namespace-prefix">namespace prefix</a> is not
  4967  null returns the concatenation of
  4968  <a href="#concept-element-namespace-prefix" title="concept-element-namespace-prefix">namespace prefix</a>,
  4969  "<code title="">:</code>", and
  4970  <a href="#concept-element-local-name" title="concept-element-local-name">local name</a>. Otherwise it
  4971  returns the <a href="#concept-element-local-name" title="concept-element-local-name">local name</a>.
  4972  (The return value is uppercased in an <a href="#html-document">HTML document</a>.)
  4973 </dl>
  4974 
  4975 <p>The <dfn id="dom-element-namespaceuri" title="dom-Element-namespaceURI"><code>namespaceURI</code></dfn>
  4976 attribute must return the <a href="#context-object">context object</a>'s
  4977 <a href="#concept-element-namespace" title="concept-element-namespace">namespace</a>.
  4978 
  4979 <p>The <dfn id="dom-element-prefix" title="dom-Element-prefix"><code>prefix</code></dfn> attribute must return the <a href="#context-object">context object</a>'s
  4980 <a href="#concept-element-namespace-prefix" title="concept-element-namespace-prefix">namespace prefix</a>.
  4981 
  4982 <p>The <dfn id="dom-element-localname" title="dom-Element-localName"><code>localName</code></dfn>
  4983 attribute must return the <a href="#context-object">context object</a>'s
  4984 <a href="#concept-element-local-name" title="concept-element-local-name">local name</a>.
  4985 
  4986 <p>The <dfn id="dom-element-tagname" title="dom-Element-tagName"><code>tagName</code></dfn> attribute
  4987 must run these steps:
  4988 <ol>
  4989  <li><p>If <a href="#context-object">context object</a>'s
  4990  <a href="#concept-element-namespace-prefix" title="concept-element-namespace-prefix">namespace prefix</a> is not
  4991  null, let <var title="">qualified name</var> be its
  4992  <a href="#concept-element-namespace-prefix" title="concept-element-namespace-prefix">namespace prefix</a>, followed