Annotation of 2006/webapi/selectors-api/Overview.html, revision 1.128

1.1       avankest    1: <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
                      2: 
1.11      avankest    3: <html lang=en-US>
1.119     lhunt       4:  <head profile="http://dublincore.org/documents/2008/08/04/dc-html/ ">
                      5:   <meta content="text/html;charset=UTF-8" http-equiv=Content-Type>
1.102     lhunt       6:   <title>Selectors API Level 1</title>
1.1       avankest    7: 
1.119     lhunt       8:   <link href="http://purl.org/dc/terms/" rel=schema.dcterms>
                      9:   <link href="http://www.w3.org/Consortium/Legal/ipr-notice#Copyright"
                     10:    rel=dcterms.rights>
                     11:   <meta content="Selectors API Level 1" name=dcterms.title>
                     12:   <meta content=text name=dcterms.type>
1.126     lhunt      13:   <meta content=2013-02-21 name=dcterms.issued>
1.119     lhunt      14:   <meta content="Anne van Kesteren" name=dcterms.creator>
                     15:   <meta content="Lachlan Hunt" name=dcterms.creator>
                     16:   <meta content=W3C name=dcterms.publisher>
1.126     lhunt      17:   <meta content="http://www.w3.org/TR/2013/REC-selectors-api-20130221/"
1.119     lhunt      18:    name=dcterms.identifier>
1.1       avankest   19:   <style type="text/css">
1.36      lhunt      20:        pre.idl { border:solid thin; background:#eee; color:#000; padding:0.5em }
1.50      lhunt      21:        pre.idl :link, pre.idl :visited { color:inherit; background:transparent }
1.20      lhunt      22: 
1.36      lhunt      23:        div.example { border-left:double; padding-left:1em }
                     24:        dfn { font-style:normal; font-weight:bolder }
                     25:        em.ct { font-style:normal; font-weight:normal; font-variant:small-caps }
                     26:        p.note {  margin-left:2em; color:green; font-style:italic; font-weight:bold }
                     27:        p.note:before { content:"Note: " }
                     28:        .issue { padding:.5em; border:solid red }
                     29:        .issue:before { content:"Issue: " }
                     30:        code { color:#FF4500; }
                     31:        code :link, code :visited { color:inherit }
                     32:        </style>
1.126     lhunt      33:   <link href="http://www.w3.org/StyleSheets/TR/W3C-REC" rel=stylesheet
1.119     lhunt      34:    type="text/css">
1.1       avankest   35: 
                     36:  <body>
1.11      avankest   37:   <div class=head>
1.31      lhunt      38:    <p><a href="http://www.w3.org/"><img alt=W3C height=48
1.119     lhunt      39:     src="http://www.w3.org/Icons/w3c_home" width=72></a>
1.1       avankest   40: 
1.102     lhunt      41:    <h1 id=title>Selectors API Level 1</h1>
1.119     lhunt      42: 
1.126     lhunt      43:    <h2 class="no-num no-toc" id=W3C-doctype>W3C Recommendation 21 February
                     44:     2013</h2>
1.1       avankest   45: 
                     46:    <dl>
1.5       avankest   47:     <dt>This Version:
1.1       avankest   48: 
1.11      avankest   49:     <dd><a
1.126     lhunt      50:      href="http://www.w3.org/TR/2013/REC-selectors-api-20130221/">http://www.w3.org/TR/2013/REC-selectors-api-20130221/</a>
1.1       avankest   51: 
1.5       avankest   52:     <dt>Latest Version:
1.1       avankest   53: 
                     54:     <dd><a
                     55:      href="http://www.w3.org/TR/selectors-api/">http://www.w3.org/TR/selectors-api/</a>
                     56: 
1.12      avankest   57:     <dt>Previous Versions:
                     58: 
                     59:     <dd><a
1.126     lhunt      60:      href="http://www.w3.org/TR/2012/PR-selectors-api-20121213/">http://www.w3.org/TR/2012/PR-selectors-api-20121213/</a>
                     61: 
                     62:     <dd><a
1.125     lhunt      63:      href="http://www.w3.org/TR/2012/WD-selectors-api-20120628/">http://www.w3.org/TR/2012/WD-selectors-api-20120628/</a>
                     64: 
                     65:     <dd><a
1.112     lhunt      66:      href="http://www.w3.org/TR/2009/CR-selectors-api-20091222/">http://www.w3.org/TR/2009/CR-selectors-api-20091222/</a>
                     67: 
                     68:     <dd><a
1.102     lhunt      69:      href="http://www.w3.org/TR/2008/WD-selectors-api-20081114/">http://www.w3.org/TR/2008/WD-selectors-api-20081114/</a>
                     70: 
                     71:     <dd><a
1.44      lhunt      72:      href="http://www.w3.org/TR/2007/WD-selectors-api-20071221/">http://www.w3.org/TR/2007/WD-selectors-api-20071221/</a>
                     73: 
                     74:     <dd><a
1.31      lhunt      75:      href="http://www.w3.org/TR/2007/WD-selectors-api-20071019/">http://www.w3.org/TR/2007/WD-selectors-api-20071019/</a>
1.29      lhunt      76: 
                     77:     <dd><a
1.12      avankest   78:      href="http://www.w3.org/TR/2006/WD-selectors-api-20060926/">http://www.w3.org/TR/2006/WD-selectors-api-20060926/</a>
1.1       avankest   79: 
                     80:     <dd><a
                     81:      href="http://www.w3.org/TR/2006/WD-selectors-api-20060525/">http://www.w3.org/TR/2006/WD-selectors-api-20060525/</a>
                     82: 
1.20      lhunt      83:     <dt>Editors:
                     84: 
1.46      lhunt      85:     <dd><a href="http://annevankesteren.nl/">Anne van Kesteren</a> (<a
                     86:      href="http://www.opera.com/">Opera Software ASA</a>) &lt;<a
                     87:      href="mailto:annevk@opera.com">annevk@opera.com</a>&gt;
                     88: 
1.29      lhunt      89:     <dd><a href="http://lachy.id.au/">Lachlan Hunt</a> (<a
                     90:      href="http://www.opera.com/">Opera Software ASA</a>) &lt;<a
1.20      lhunt      91:      href="mailto:lachlan.hunt@lachy.id.au">lachlan.hunt@lachy.id.au</a>&gt;
1.1       avankest   92:    </dl>
                     93: 
1.126     lhunt      94:    <p>Please refer to the <a
1.128   ! lhunt      95:     href="http://dev.w3.org/2006/webapi/selectors-api/errata/errata-l1.html"><strong>errata</strong></a>
        !            96:     for this document, which may include some normative corrections.
1.126     lhunt      97: 
                     98:    <p>See also <a
                     99:     href="http://www.w3.org/2003/03/Translations/byTechnology?technology=selectors-api"><strong>translations</strong></a>.
                    100: 
1.11      avankest  101:    <p class=copyright><a
1.1       avankest  102:     href="http://www.w3.org/Consortium/Legal/ipr-notice#Copyright">Copyright</a>
1.126     lhunt     103:     © 2006-2013 <a href="http://www.w3.org/"><acronym
1.106     lhunt     104:     title="World Wide Web Consortium">W3C</acronym></a><sup>®</sup> (<a
                    105:     href="http://www.csail.mit.edu/"><acronym
                    106:     title="Massachusetts Institute of Technology">MIT</acronym></a>, <a
                    107:     href="http://www.ercim.eu/"><acronym
                    108:     title="European Research Consortium for Informatics and Mathematics">ERCIM</acronym></a>,
1.126     lhunt     109:     <a href="http://www.keio.ac.jp/">Keio</a>, <a
                    110:     href="http://ev.buaa.edu.cn/">Beihang</a>), All Rights Reserved. W3C <a
1.31      lhunt     111:     href="http://www.w3.org/Consortium/Legal/ipr-notice#Legal_Disclaimer">liability</a>,
                    112:     <a
                    113:     href="http://www.w3.org/Consortium/Legal/ipr-notice#W3C_Trademarks">trademark</a>
                    114:     and <a
                    115:     href="http://www.w3.org/Consortium/Legal/copyright-documents">document
1.119     lhunt     116:     use</a> rules apply.
1.33      lhunt     117:   </div>
1.1       avankest  118: 
                    119:   <hr>
                    120: 
1.11      avankest  121:   <h2 class="no-num no-toc" id=abstract>Abstract</h2>
1.1       avankest  122: 
1.23      lhunt     123:   <p>Selectors, which are widely used in CSS, are patterns that match against
1.54      lhunt     124:    elements in a tree structure <a href="#SELECT"
                    125:    rel=biblioentry>[SELECT]<!--{{!SELECT}}--></a><a href="#CSS21"
1.69      lhunt     126:    rel=biblioentry>[CSS21]<!--{{CSS21}}--></a>. The Selectors API
1.108     lhunt     127:    specification defines methods for retrieving <a
                    128:    href="#element"><code>Element</code></a> nodes from the <abbr
                    129:    title="Document Object Model">DOM</abbr> by matching against a group of
                    130:    selectors. It is often desirable to perform DOM operations on a specific
                    131:    set of elements in a document. These methods simplify the process of
                    132:    acquiring specific elements, especially compared with the more verbose
                    133:    techniques defined and used in the past.
1.1       avankest  134: 
1.11      avankest  135:   <h2 class="no-num no-toc" id=sotd>Status of this Document</h2>
1.1       avankest  136: 
                    137:   <p><em>This section describes the status of this document at the time of
                    138:    its publication. Other documents may supersede this document. A list of
                    139:    current W3C publications and the latest revision of this technical report
                    140:    can be found in the <a href="http://www.w3.org/TR/">W3C technical reports
                    141:    index</a> at http://www.w3.org/TR/.</em>
                    142: 
1.125     lhunt     143:   <p>The <a href="http://www.w3.org/2008/webapps/">Web Applications (WebApps)
                    144:    Working Group</a> has developed a comprehensive <a
1.112     lhunt     145:    href="http://dev.w3.org/2006/webapi/selectors-api-testsuite/">Selectors
1.125     lhunt     146:    API test suite</a> and has demonstrated interoperability of the features
                    147:    among implementations. Please see the Working Group's <a
                    148:    href="http://dev.w3.org/2006/webapi/selectors-api-testsuite/level1-baseline-report.html"
                    149:    title="Selectors API Implementation Report: Baseline Tests">implementation
                    150:    report</a>.
                    151: 
1.126     lhunt     152:   <p>Please send comments about this document to <a
                    153:    href="mailto:public-webapps@w3.org">public-webapps@w3.org</a> (<a
                    154:    href="http://lists.w3.org/Archives/Public/public-webapps/">public
                    155:    archive</a>) with <kbd>[selectors-api]</kbd> in the subject. (Please note
                    156:    that a different list was used until mid 2008, so some old messages are <a
                    157:    href="http://lists.w3.org/Archives/Public/public-webapi/">archived there
                    158:    instead</a>).
1.1       avankest  159: 
1.29      lhunt     160:   <p>This document was developed by the <a
1.57      lhunt     161:    href="http://www.w3.org/2008/webapps/">Web Applications Working Group</a>.
1.125     lhunt     162:    A complete <a
                    163:    href="http://dev.w3.org/cvsweb/2006/webapi/selectors-api/">list of
                    164:    changes</a> to this document is available.
                    165: 
1.126     lhunt     166:   <p>This document has been reviewed by W3C Members, by software developers,
                    167:    and by other W3C groups and interested parties, and is endorsed by the
                    168:    Director as a W3C Recommendation. It is a stable document and may be used
                    169:    as reference material or cited from another document. W3C's role in making
                    170:    the Recommendation is to draw attention to the specification and to
                    171:    promote its widespread deployment. This enhances the functionality and
                    172:    interoperability of the Web.
1.1       avankest  173: 
                    174:   <p>This document was produced by a group operating under the <a
                    175:    href="http://www.w3.org/Consortium/Patent-Policy-20040205/">5 February
                    176:    2004 W3C Patent Policy</a>. W3C maintains a <a
1.77      lhunt     177:    href="http://www.w3.org/2004/01/pp-impl/42538/status"
1.11      avankest  178:    rel=disclosure>public list of any patent disclosures</a> made in
1.1       avankest  179:    connection with the deliverables of the group; that page also includes
                    180:    instructions for disclosing a patent. An individual who has actual
                    181:    knowledge of a patent which the individual believes contains <a
                    182:    href="http://www.w3.org/Consortium/Patent-Policy-20040205/#def-essential">Essential
1.31      lhunt     183:    Claim(s)</a> must disclose the information in accordance with <a
1.1       avankest  184:    href="http://www.w3.org/Consortium/Patent-Policy-20040205/#sec-Disclosure">section
                    185:    6 of the W3C Patent Policy</a>.
                    186: 
1.11      avankest  187:   <h2 class="no-num no-toc" id=toc>Table of Contents</h2>
1.1       avankest  188:   <!--begin-toc-->
                    189: 
1.11      avankest  190:   <ul class=toc>
1.102     lhunt     191:    <li><a href="#introduction"><span class=secno>1. </span>Introduction</a>
1.11      avankest  192:     <ul class=toc>
1.102     lhunt     193:      <li><a href="#examples"><span class=secno>1.1. </span>Examples</a>
1.49      lhunt     194:     </ul>
1.1       avankest  195: 
1.102     lhunt     196:    <li><a href="#conformance"><span class=secno>2. </span>Conformance
1.49      lhunt     197:     Requirements</a>
                    198:     <ul class=toc>
1.102     lhunt     199:      <li><a href="#terminology"><span class=secno>2.1. </span>Terminology and
1.49      lhunt     200:       Conventions</a>
                    201:     </ul>
1.1       avankest  202: 
1.102     lhunt     203:    <li><a href="#interoperability"><span class=secno>3.
1.49      lhunt     204:     </span>Interoperability Considerations</a>
                    205:     <ul class=toc>
1.102     lhunt     206:      <li><a href="#extensibility"><span class=secno>3.1.
1.49      lhunt     207:       </span>Extensibility</a>
                    208:     </ul>
                    209: 
1.102     lhunt     210:    <li><a href="#security"><span class=secno>4. </span>Security
1.49      lhunt     211:     Considerations</a>
1.21      lhunt     212: 
1.102     lhunt     213:    <li><a href="#privacy"><span class=secno>5. </span>Privacy Considerations
1.49      lhunt     214:     </a>
1.1       avankest  215: 
1.102     lhunt     216:    <li><a href="#the-apis"><span class=secno>6. </span>The APIs</a>
1.16      avankest  217:     <ul class=toc>
1.108     lhunt     218:      <li><a href="#interface-definitions"><span class=secno>6.1.
                    219:       </span>Interface Definitions</a>
1.99      lhunt     220: 
1.108     lhunt     221:      <li><a href="#findelements"><span class=secno>6.2. </span>Finding
                    222:       Elements</a>
                    223: 
                    224:      <li><a href="#grammar"><span class=secno>6.3. </span>Grammar</a>
                    225: 
                    226:      <li><a href="#processing-selectors"><span class=secno>6.4.
1.99      lhunt     227:       </span>Processing Selectors</a>
                    228: 
1.108     lhunt     229:      <li><a href="#resolving-namespaces"><span class=secno>6.5.
1.87      lhunt     230:       </span>Resolving Namespaces</a>
1.51      lhunt     231:     </ul>
1.50      lhunt     232: 
1.119     lhunt     233:    <li><a href="#examples0"><span class=secno>7. </span>Examples</a>
1.64      lhunt     234: 
1.11      avankest  235:    <li class=no-num><a href="#references">References</a>
1.54      lhunt     236:     <ul class=toc>
                    237:      <li class=no-num><a href="#normative-references">Normative
                    238:       references</a>
                    239: 
1.84      lhunt     240:      <li class=no-num><a href="#informative-references">Informative
                    241:       references</a>
1.54      lhunt     242:     </ul>
1.1       avankest  243: 
1.11      avankest  244:    <li class=no-num><a href="#acknowledgements">Acknowledgements</a>
1.1       avankest  245:   </ul>
                    246:   <!--end-toc-->
                    247: 
1.102     lhunt     248:   <h2 id=introduction><span class=secno>1. </span>Introduction</h2>
1.1       avankest  249: 
                    250:   <p><em>This section is non-normative.</em>
                    251: 
1.108     lhunt     252:   <p>This specification provides methods for selecting and testing elements
1.115     lhunt     253:    based on whether or not they match a given selector. With these methods,
                    254:    it is easier to match a set of <a href="#element"><code>Element</code></a>
                    255:    nodes based on specific criteria, than having to subsequently filter the
                    256:    result of calling other methods like <code>getElementsByTagName()</code>.
1.10      avankest  257: 
1.102     lhunt     258:   <h3 id=examples><span class=secno>1.1. </span>Examples</h3>
1.1       avankest  259: 
                    260:   <p><em>This section is non-normative.</em>
                    261: 
1.121     lhunt     262:   <p>Some ECMAScript <a href="#ECMA-262-5.1"
                    263:    rel=biblioentry>[ECMA-262-5.1]<!--{{ECMA-262-5.1}}--></a> examples:
1.1       avankest  264: 
1.14      avankest  265:   <div class=example>
1.119     lhunt     266:    <p>This is an example table written in HTML 4.01.
1.22      lhunt     267: 
1.20      lhunt     268:    <pre>&lt;table id="score">
                    269:   &lt;thead>
                    270:     &lt;tr>
                    271:       &lt;th>Test
                    272:       &lt;th>Result
                    273:   &lt;tfoot>
                    274:     &lt;tr>
                    275:       &lt;th>Average
                    276:       &lt;td>82%
                    277:   &lt;tbody>
                    278:     &lt;tr>
                    279:       &lt;td>A
                    280:       &lt;td>87%
                    281:     &lt;tr>
                    282:       &lt;td>B
                    283:       &lt;td>78%
                    284:     &lt;tr>
                    285:       &lt;td>C
                    286:       &lt;td>81%
                    287: &lt;/table></pre>
                    288: 
                    289:    <p>In order to obtain the cells containing the results in the table, which
                    290:     might be done, for example, to plot the values on a graph, there are at
                    291:     least two approaches that may be taken. Using only the APIs from DOM
                    292:     Level 2, it requires a script like the following that iterates through
                    293:     each <code>tr</code> within each <code>tbody</code> in the
1.119     lhunt     294:     <code>table</code> to find the second cell of each row.
1.20      lhunt     295: 
                    296:    <pre>var table = document.getElementById("score");
1.23      lhunt     297: var groups = table.tBodies;
                    298: var rows = null;
1.24      lhunt     299: var cells = [];
1.20      lhunt     300: 
1.23      lhunt     301: for (var i = 0; i &lt; groups.length; i++) {
                    302:   rows = groups[i].rows;
                    303:   for (var j = 0; j &lt; rows.length; j++) {
                    304:     cells.push(rows[j].cells[1]);
1.20      lhunt     305:   }
1.36      lhunt     306: }</pre>
1.20      lhunt     307: 
1.46      lhunt     308:    <p>Alternatively, using the <code
                    309:     title=document-selectallelements>querySelectorAll()</code> method, that
1.119     lhunt     310:     script becomes much more concise.
1.20      lhunt     311: 
1.36      lhunt     312:    <pre>var cells = document.querySelectorAll("#score&gt;tbody&gt;tr&gt;td:nth-of-type(2)");</pre>
1.41      lhunt     313: 
1.84      lhunt     314:    <p>Note that the script operates on the DOM and works independently from
                    315:     the syntax used to create the document. Thus this script will also work
                    316:     correctly for an equivalent table created from well-formed XHTML instead
                    317:     of HTML, or dynamically created and inserted into a document using DOM
1.119     lhunt     318:     APIs.
1.20      lhunt     319:   </div>
                    320: 
1.102     lhunt     321:   <h2 id=conformance><span class=secno>2. </span>Conformance Requirements</h2>
1.1       avankest  322: 
1.21      lhunt     323:   <p>All diagrams, examples and notes in this specification are
1.20      lhunt     324:    non-normative, as are all sections explicitly marked non-normative.
                    325:    Everything else in this specification is normative.
1.1       avankest  326: 
1.73      lhunt     327:   <p>The key words <em class=ct>must</em>, <em class=ct>must not</em>, <em
                    328:    class=ct>should</em>, <em class=ct>may</em> and <em
                    329:    class=ct>recommended</em> in the normative parts of this document are to
                    330:    be interpreted as described in RFC 2119 <a href="#RFC2119"
1.54      lhunt     331:    rel=biblioentry>[RFC2119]<!--{{!RFC2119}}--></a>.
1.1       avankest  332: 
1.11      avankest  333:   <p>The following conformance classes are defined (and considered) by this
                    334:    specification:
1.1       avankest  335: 
                    336:   <dl>
1.87      lhunt     337:    <dt><dfn id=conforming-user-agent>conforming user agent</dfn>
1.1       avankest  338: 
1.108     lhunt     339:    <dd>A user agent that implements the interfaces described in this
                    340:     specification and conforms to all <em class=ct>must</em>-level criteria
                    341:     that apply to implementations.
1.22      lhunt     342: 
1.87      lhunt     343:    <dt><dfn id=conforming-application>conforming application</dfn>
1.22      lhunt     344: 
                    345:    <dd>An application that uses the interfaces defined in this specification
1.36      lhunt     346:     and conforms to all <em class=ct>must</em>-level criteria that apply to
                    347:     applications.
1.1       avankest  348:   </dl>
                    349: 
1.102     lhunt     350:   <h3 id=terminology><span class=secno>2.1. </span>Terminology and
                    351:    Conventions</h3>
1.16      avankest  352: 
1.54      lhunt     353:   <p>The terminology used in this specification is that from Selectors <a
                    354:    href="#SELECT" rel=biblioentry>[SELECT]<!--{{!SELECT}}--></a>.
1.16      avankest  355: 
1.108     lhunt     356:   <p>The following features are defined in the DOM Level 3 Core specification
                    357:    <a href="#DOM-LEVEL-3-CORE"
                    358:    rel=biblioentry>[DOM-LEVEL-3-CORE]<!--{{!DOM-LEVEL-3-CORE}}--></a>:
                    359: 
                    360:   <ul>
                    361:    <li><dfn id=document title=dom-document><code>Document</code></dfn>
                    362:     interface.
                    363: 
                    364:    <li><dfn id=documentfragment><code>DocumentFragment</code></dfn>
                    365:     interface.
                    366: 
                    367:    <li><dfn id=element><code>Element</code></dfn> interface.
                    368: 
                    369:    <li><dfn id=nodelist><code>NodeList</code></dfn> interface.
                    370:   </ul>
                    371: 
1.73      lhunt     372:   <p>Conformance requirements phrased as algorithms or specific steps <em
                    373:    class=ct>may</em> be implemented in any manner, so long as the end result
                    374:    is equivalent.
1.16      avankest  375: 
1.90      lhunt     376:   <p>The IDL used in this specification uses the syntax defined in Web IDL <a
1.120     lhunt     377:    href="#DOM-BINDINGS"
                    378:    rel=biblioentry>[DOM-BINDINGS]<!--{{!DOM-BINDINGS}}--></a>.
1.90      lhunt     379: 
1.23      lhunt     380:   <p>The construction "<code>Foo</code> object", where <code>Foo</code> is
                    381:    actually an interface, is sometimes used instead of the more accurate
1.24      lhunt     382:    "object implementing the <code>Foo</code> interface".
1.23      lhunt     383: 
1.102     lhunt     384:   <h2 id=interoperability><span class=secno>3. </span>Interoperability
1.49      lhunt     385:    Considerations</h2>
1.16      avankest  386: 
1.23      lhunt     387:   <p><em>This section is non-normative.</em>
                    388: 
1.65      lhunt     389:   <p>Some implementations might have different levels of support for
                    390:    Selectors. If some implementations lack support for some selectors, then
1.87      lhunt     391:    the use of such selectors will result in those implementations failing to
                    392:    return the expected results. Authors are advised to check for the DOM
                    393:    Exceptions thrown by these APIs and provide a fallback for graceful
                    394:    degradation.
1.19      avankest  395: 
1.102     lhunt     396:   <h3 id=extensibility><span class=secno>3.1. </span>Extensibility</h3>
1.5       avankest  397: 
                    398:   <p><em>This section is non-normative.</em>
                    399: 
                    400:   <p>Extensions of the APIs defined in this specification are <em>strongly
1.36      lhunt     401:    discouraged</em>. Implementors, Working Groups and other interested
                    402:    parties should discuss extensions on a relevant public forum, such as <a
1.57      lhunt     403:    href="mailto:public-webapps@w3.org">public-webapps@w3.org</a>.
1.5       avankest  404: 
1.102     lhunt     405:   <h2 id=security><span class=secno>4. </span>Security Considerations</h2>
1.11      avankest  406: 
                    407:   <p>It is expected that implementing this specification introduces no new
1.21      lhunt     408:    security risks for users.
                    409: 
1.62      lhunt     410:   <p>If, at any time, the implementation detects a situation which would
1.73      lhunt     411:    violate security policies, the implementation <em class=ct>may</em> abort
                    412:    and raise a security exception. If any other error condition occurs which
                    413:    is not covered directly by this or any other relevant specification, the
                    414:    implementation <em class=ct>may</em> abort and raise an appropriate,
1.62      lhunt     415:    language-binding-specific or implementation-specific exception.
                    416: 
1.102     lhunt     417:   <h2 id=privacy><span class=secno>5. </span>Privacy Considerations</h2>
1.11      avankest  418: 
1.20      lhunt     419:   <p>History theft is a potential privacy issue because the
1.54      lhunt     420:    <code>:visited</code> pseudo-class in Selectors <a href="#SELECT"
                    421:    rel=biblioentry>[SELECT]<!--{{!SELECT}}--></a> allows authors to query
                    422:    which links have been visited.
1.20      lhunt     423: 
                    424:   <p class=note>This is not a new problem, as it can already be exploited
                    425:    using existing CSS and DOM APIs, such as <code>getComputedStyle()</code>
1.54      lhunt     426:    <a href="#DOM-LEVEL-2-STYLE"
                    427:    rel=biblioentry>[DOM-LEVEL-2-STYLE]<!--{{DOM-LEVEL-2-STYLE}}--></a>.
1.20      lhunt     428: 
                    429:   <div class=example>
1.36      lhunt     430:    <p>In this example, <var>vlinks</var> will acquire a list of links that
                    431:     the user has visited. The author can then obtain the URIs and potentially
1.119     lhunt     432:     exploit this knowledge.
1.20      lhunt     433: 
1.27      lhunt     434:    <pre>var vlinks = document.querySelectorAll(":visited");
1.20      lhunt     435: for (var i = 0; i &lt; vlinks.length; i++) {
                    436:   doSomethingEvil(vlinks[i].href);
                    437: }</pre>
                    438:   </div>
                    439: 
                    440:   <p>As <a href="http://www.w3.org/TR/css3-selectors/#link">defined in
1.54      lhunt     441:    <cite>Selectors</cite></a> (<a href="#SELECT"
                    442:    rel=biblioentry>[SELECT]<!--{{!SELECT}}--></a>, section 6.6.1), user
                    443:    agents <em class=ct>may</em> treat all links as unvisited links. It is <em
1.47      lhunt     444:    class=ct>recommended</em> that implementations behave consistently with
                    445:    other uses of Selectors supported by the user agent.
1.11      avankest  446: 
1.102     lhunt     447:   <h2 id=the-apis><span class=secno>6. </span>The APIs</h2>
1.36      lhunt     448: 
                    449:   <p>The term <dfn id=first>first</dfn> used in the definitions of the
1.99      lhunt     450:    methods defined in this specification means <em>first in document
                    451:    order</em>. The term <dfn id=document-order>document order</dfn> means a
                    452:    depth-first pre-order traversal of the DOM tree or subtree in question.
                    453:    The term <dfn id=context-node>context node</dfn> refers to the node upon
1.108     lhunt     454:    which the method was invoked. The term <dfn id=subtrees>subtrees</dfn>
                    455:    refers to the collection of elements that are descendants of the <a
                    456:    href="#context-node">context node</a>. The term <dfn
1.99      lhunt     457:    id=matching-element-node>matching <code>Element</code> node</dfn> refers
1.108     lhunt     458:    to an <a href="#element"><code>Element</code></a> node that matches the <a
                    459:    href="#selector-string">selector string</a> (<var>selectors</var>) that
                    460:    was passed to the method, according to the rules for matching elements
                    461:    defined in Selectors <a href="#SELECT"
1.102     lhunt     462:    rel=biblioentry>[SELECT]<!--{{!SELECT}}--></a>.
1.65      lhunt     463: 
1.108     lhunt     464:   <h3 id=interface-definitions><span class=secno>6.1. </span>Interface
                    465:    Definitions</h3>
1.99      lhunt     466: 
1.108     lhunt     467:   <pre class=idl>partial interface <a href="#document"
                    468:    title=dom-document>Document</a> {
1.110     lhunt     469:   Element?  <a href="#queryselector"
1.108     lhunt     470:    title=queryselector>querySelector</a>(DOMString selectors);
                    471:   NodeList  <a
                    472:    href="#queryselectorall"
                    473:    title=queryselectorall>querySelectorAll</a>(DOMString selectors);
                    474: };
                    475: 
                    476: partial interface <a
                    477:    href="#documentfragment">DocumentFragment</a> {
1.110     lhunt     478:   Element?  <a
1.106     lhunt     479:    href="#queryselector"
1.108     lhunt     480:    title=queryselector>querySelector</a>(DOMString selectors);
                    481:   NodeList  <a
                    482:    href="#queryselectorall"
                    483:    title=queryselectorall>querySelectorAll</a>(DOMString selectors);
                    484: };
                    485: 
                    486: partial interface <a
                    487:    href="#element">Element</a> {
1.110     lhunt     488:   Element?  <a href="#queryselector"
1.108     lhunt     489:    title=queryselector>querySelector</a>(DOMString selectors);
                    490:   NodeList  <a
1.106     lhunt     491:    href="#queryselectorall"
1.108     lhunt     492:    title=queryselectorall>querySelectorAll</a>(DOMString selectors);
                    493: };
                    494: </pre>
                    495: 
                    496:   <h3 id=findelements><span class=secno>6.2. </span>Finding Elements</h3>
                    497: 
                    498:   <p>The <var>selectors</var> argument for the <a
                    499:    href="#queryselector"><code>querySelector</code></a> and <a
                    500:    href="#queryselectorall"><code>querySelectorAll</code></a> methods accepts
                    501:    a <a href="#selector-string">selector string</a>.
1.99      lhunt     502: 
1.53      lhunt     503:   <p>The <dfn id=queryselector
1.108     lhunt     504:    title=queryselector><code>querySelector()</code></dfn> methods on the <a
                    505:    href="#document"><code title=dom-document>Document</code></a>, <a
                    506:    href="#documentfragment"><code>DocumentFragment</code></a>, and <a
                    507:    href="#element"><code>Element</code></a> interfaces <em class=ct>must</em>
                    508:    return the <a href="#first">first</a> matching <a
                    509:    href="#element"><code>Element</code></a> node within the <a
                    510:    href="#subtrees">subtrees</a> of the <a href="#context-node">context
                    511:    node</a>. If there is no matching <a
                    512:    href="#element"><code>Element</code></a>, the method <em
                    513:    class=ct>must</em> return <code>null</code>.
1.1       avankest  514: 
1.53      lhunt     515:   <p>The <dfn id=queryselectorall
1.108     lhunt     516:    title=queryselectorall><code>querySelectorAll()</code></dfn> methods on
                    517:    the <a href="#document"><code title=dom-document>Document</code></a>, <a
                    518:    href="#documentfragment"><code>DocumentFragment</code></a>, and <a
                    519:    href="#element"><code>Element</code></a> interfaces <em class=ct>must</em>
                    520:    return a <a href="#nodelist"><code>NodeList</code></a> containing all of
                    521:    the matching <a href="#element"><code>Element</code></a> nodes within the
                    522:    <a href="#subtrees">subtrees</a> of the <a href="#context-node">context
                    523:    node</a>, in <a href="#document-order">document order</a>. If there are no
                    524:    matching nodes, the method <em class=ct>must</em> return an empty <a
                    525:    href="#nodelist"><code>NodeList</code></a>.
1.99      lhunt     526: 
1.122     lhunt     527:   <p>When either <a href="#queryselector"><code>querySelector</code></a> or
                    528:    <a href="#queryselectorall"><code>querySelectorAll</code></a> are invoked,
                    529:    the implementation <em class=ct>must</em> follow these steps:
1.114     lhunt     530: 
                    531:   <ol>
                    532:    <li>
                    533:     <p>Let <var>parsed selector</var> be the result of running the algorithm
                    534:      to <a href="#parse-a-selector">parse a selector</a> with
1.118     lhunt     535:      <var>selectors</var> as the input.
1.114     lhunt     536: 
                    537:    <li>
                    538:     <p>The implementation must then run the algorithm to <a
                    539:      href="#evaluate-a-selector">evaluate a selector</a> against element
                    540:      nodes in the specified <span title=concept-tree>tree</span> or <a
                    541:      href="#subtrees">subtrees</a> using <var>parsed selector</var> as the
                    542:      selector to return the required result for the invoked method.
                    543:   </ol>
                    544: 
1.108     lhunt     545:   <p>The <a href="#nodelist"><code>NodeList</code></a> object returned by the
1.119     lhunt     546:    <code>querySelectorAll()</code> method <em class=ct>must</em> be static,
                    547:    not <a href="http://www.w3.org/TR/DOM-Level-3-Core/core.html#td-live"
1.99      lhunt     548:    title="Document Object Model Core">live</a> (<a href="#DOM-LEVEL-3-CORE"
                    549:    rel=biblioentry>[DOM-LEVEL-3-CORE]<!--{{!DOM-LEVEL-3-CORE}}--></a>,
                    550:    section 1.1.1). Subsequent changes to the structure of the underlying
1.108     lhunt     551:    document <em class=ct>must not</em> be reflected in the <a
                    552:    href="#nodelist"><code>NodeList</code></a> object. This means that the
                    553:    object will instead contain a list of matching <a
                    554:    href="#element"><code>Element</code></a> nodes that were in the document
                    555:    at the time the list was created.
1.99      lhunt     556: 
1.108     lhunt     557:   <h3 id=grammar><span class=secno>6.3. </span>Grammar</h3>
1.99      lhunt     558: 
1.108     lhunt     559:   <p>A <dfn id=selector-string>selector string</dfn> is a list of one or more
                    560:    <a href="http://dev.w3.org/csswg/selectors4/#complex">group of
1.99      lhunt     561:    selectors</a> (<a href="#SELECT"
1.108     lhunt     562:    rel=biblioentry>[SELECT]<!--{{!SELECT}}--></a>, section 5) that <em
                    563:    class=ct>may</em> be surrounded by whitespace and matches the
                    564:    <code>dom_selectors_group</code> production.
                    565: 
                    566:   <pre>
                    567: dom_selectors_group
                    568:   : S* [ selectors_group ] S*
                    569:   ;
1.114     lhunt     570: </pre>
1.108     lhunt     571: 
                    572:   <p>The productions for <code>selectors_group</code> is defined in Selectors
                    573:    Level 3 (<a href="#SELECT" rel=biblioentry>[SELECT]<!--{{!SELECT}}--></a>,
                    574:    section 10.1). These groups of selectors <em class=ct>should not</em> use
                    575:    <a href="#namespace-prefix-needs-to-be-resolved"
1.87      lhunt     576:    title=need-to-resolve>namespace prefixes that need to be resolved</a>.
1.36      lhunt     577: 
1.96      lhunt     578:   <p class=note>Implementers are advised that if <code>null</code> or
                    579:    <code>undefined</code> are passed as the value of the <var>selectors</var>
1.120     lhunt     580:    parameter, they are to be handled as defined in WebIDL <a
                    581:    href="#DOM-BINDINGS"
                    582:    rel=biblioentry>[DOM-BINDINGS]<!--{{!DOM-BINDINGS}}--></a>. Authors are
                    583:    advised to avoid passing these values.
1.96      lhunt     584: 
1.36      lhunt     585:   <p class=note>Authors are advised that while the use of pseudo-elements in
                    586:    selectors is permitted, they will not match any elements in the document,
                    587:    and thus would not result in any elements being returned. Therefore,
1.73      lhunt     588:    authors are advised to avoid the use of pseudo-elements in selectors that
                    589:    are passed to the methods defined in this specification.
1.36      lhunt     590: 
1.108     lhunt     591:   <h3 id=processing-selectors><span class=secno>6.4. </span>Processing
                    592:    Selectors</h3>
                    593: 
                    594:   <p>The steps to <dfn id=parse-a-selector>parse a selector</dfn> are as
                    595:    follows:
                    596: 
                    597:   <ol>
                    598:    <li>
                    599:     <p>Let <var>selectors</var> be the <a href="#selector-string">selector
                    600:      string</a> input to this algorithm.
                    601: 
                    602:    <li>
1.122     lhunt     603:     <p>Let <var>result</var> be the group of selectors returned as a result
                    604:      of parsing the <var>selectors</var> according to the grammar for
                    605:      <code>dom_selectors_group</code> defined above.
1.108     lhunt     606: 
                    607:    <li>
1.122     lhunt     608:     <p>If <var>result</var> is <a
1.123     lhunt     609:      href="http://www.w3.org/TR/css3-selectors/#Conformance">invalid</a> (<a
                    610:      href="#SELECT" rel=biblioentry>[SELECT]<!--{{!SELECT}}--></a>, section
                    611:      12), <a
                    612:      href="http://www.w3.org/TR/DOM-Level-3-Core/core.html#DOMException-SYNTAX_ERR">raisea
1.108     lhunt     613:      a <code>SYNTAX_ERR</code> exception</a> (<a href="#DOM-LEVEL-3-CORE"
                    614:      rel=biblioentry>[DOM-LEVEL-3-CORE]<!--{{!DOM-LEVEL-3-CORE}}--></a>,
1.119     lhunt     615:      section 1.4) and abort this algorithm.
1.108     lhunt     616: 
                    617:    <li>Return <var>result</var>.
                    618:   </ol>
                    619: 
                    620:   <p>The steps to <dfn id=evaluate-a-selector>evaluate a selector</dfn> are
                    621:    as follows:
                    622: 
                    623:   <ol>
                    624:    <li>
                    625:     <p>Let <var title="">element</var> be the element being evaluated.
                    626: 
                    627:    <li>
                    628:     <p>Let <var>selector group</var> be the selector input into this
                    629:      algotihm.
                    630: 
                    631:    <li>
                    632:     <p>If any selector in <var>selector group</var> matches <var
                    633:      title="">element</var>, return true. Otherwise, return false.
                    634:   </ol>
                    635: 
                    636:   <p>Selectors are evaluated against a given element in the context of the
                    637:    entire DOM tree in which the element is located.
1.20      lhunt     638: 
1.50      lhunt     639:   <p>If the user agent also supports some level of CSS, the implementation
                    640:    <em class=ct>should</em> support the same set of selectors in both these
                    641:    APIs and CSS.
1.1       avankest  642: 
1.108     lhunt     643:   <h3 id=resolving-namespaces><span class=secno>6.5. </span>Resolving
1.87      lhunt     644:    Namespaces</h3>
1.50      lhunt     645: 
1.87      lhunt     646:   <p>If the group of selectors include <a
                    647:    href="#namespace-prefix-needs-to-be-resolved"
1.65      lhunt     648:    title=need-to-resolve>namespace prefixes that need to be resolved</a>, the
1.73      lhunt     649:    implementation <em class=ct>must</em> <a
1.109     lhunt     650:    href="http://www.w3.org/TR/DOM-Level-3-Core/core.html#DOMException-SYNTAX_ERR">raise
                    651:    a <code>SYNTAX_ERR</code> exception</a> (<a href="#DOM-LEVEL-3-CORE"
1.54      lhunt     652:    rel=biblioentry>[DOM-LEVEL-3-CORE]<!--{{!DOM-LEVEL-3-CORE}}--></a>,
                    653:    section 1.4).
1.50      lhunt     654: 
1.86      lhunt     655:   <p class=note>This specification does not provide support for resolving
                    656:    arbitrary namespace prefixes. However, support for a namespace prefix
                    657:    resolution mechanism may be considered for inclusion in a future version
                    658:    of this specification.
                    659: 
1.87      lhunt     660:   <p>A <dfn id=namespace-prefix-needs-to-be-resolved
                    661:    title=need-to-resolve>namespace prefix needs to be resolved</dfn> if the
                    662:    namespace component is neither empty (e.g. <code>|div</code>),
                    663:    representing the null namespace, or an asterisk (e.g. <code>*|div</code>),
                    664:    representing any namespace. Since the asterisk or empty namespace prefix
                    665:    do not need to be resolved, implementations that support the namespace
                    666:    syntax in Selectors <em class=ct>must</em> support these. <a
                    667:    href="#SELECT" rel=biblioentry>[SELECT]<!--{{!SELECT}}--></a>
1.60      lhunt     668: 
1.119     lhunt     669:   <h2 id=examples0><span class=secno>7. </span>Examples</h2>
1.64      lhunt     670: 
1.22      lhunt     671:   <div class=example>
1.119     lhunt     672:    <p>The following examples make use of this sample XHTML document.
1.20      lhunt     673: 
1.72      lhunt     674:    <pre>&lt;html xmlns="http://www.w3.org/1999/xhtml">
1.22      lhunt     675:   &lt;head>
                    676:     &lt;title&gt;Selectors API Example&lt;/title&gt;
                    677:   &lt;/head>
                    678:   &lt;body>
1.72      lhunt     679:     &lt;div id="foo"&gt;
                    680:       &lt;p class="warning"&gt;This is a sample warning&lt;/p&gt;
                    681:       &lt;p class="error"&gt;This is a sample error&lt;/p&gt;
                    682:     &lt;/div&gt;
                    683:     &lt;div id="bar"&gt;
                    684:       &lt;p&gt;...&lt;/p&gt;
                    685:     &lt;/div&gt;
1.22      lhunt     686:   &lt;/body>
1.36      lhunt     687: &lt;/html></pre>
1.20      lhunt     688: 
1.65      lhunt     689:    <p>The methods accept a group of selectors (comma separated) as the
                    690:     argument. The following example would select all <code>p</code> elements
                    691:     in the document that have a class of either "<code>error</code>" or
1.119     lhunt     692:     "<code>warning</code>".
1.65      lhunt     693: 
                    694:    <pre>var alerts = document.querySelectorAll("p.warning, p.error");</pre>
1.21      lhunt     695: 
1.65      lhunt     696:    <p>The <code title=document-selectelement>querySelector()</code> methods
                    697:     also accept a group of selectors and they will return the first element
1.119     lhunt     698:     (if any) that matches any of the selectors in the group.
1.65      lhunt     699: 
                    700:    <pre>var x = document.querySelector("#foo, #bar");</pre>
                    701: 
                    702:    <p><var>x</var> would contain the first element in the document with an ID
1.94      lhunt     703:     of either <code>foo</code> or <code>bar</code>, or <code>null</code> if
                    704:     there is no such element. In the sample document above, it would select
                    705:     the <code>div</code> element with the ID of <code>foo</code> because it
1.114     lhunt     706:     is first in <a href="#document-order">document order</a>. The order of
                    707:     the selectors used in the parameter has no effect and would have the same
1.119     lhunt     708:     result if the order were reversed, as in:
1.81      lhunt     709: 
                    710:    <pre>var x = document.querySelector("#bar, #foo");</pre>
                    711: 
                    712:    <p>The methods can also be invoked on elements. In the following example,
                    713:     assume the event handler is registered on an element, and thus the method
1.119     lhunt     714:     is invoked on the target element of the event.
1.22      lhunt     715: 
1.65      lhunt     716:    <pre>function handle(evt) {
                    717:   var x = evt.target.querySelector("span");
                    718:   ...
                    719:   // Do something with x
1.21      lhunt     720: }</pre>
1.14      avankest  721: 
1.74      lhunt     722:    <p>Even though the method is invoked on an element, selectors are still
                    723:     evaluated in the context of the entire document. In the following
                    724:     example, the method will still match the <code>div</code> element's child
                    725:     <code>p</code> element, even though the <code>body</code> element is not
1.119     lhunt     726:     a descendant of the <code>div</code> element itself.
1.74      lhunt     727: 
                    728:    <pre>var div = document.getElementById("bar");
1.80      lhunt     729: var p = div.querySelector("body p");</pre>
1.74      lhunt     730: 
1.119     lhunt     731:    <p>Given this sample fragment that contains a list as a navigation menu:
1.72      lhunt     732: 
                    733:    <pre>&lt;ul class="nav"&gt;
                    734:   &lt;li&gt;&lt;a href="/"&gt;Home&lt;/a&gt;&lt;/li&gt;
                    735:   &lt;li&gt;&lt;a href="/products"&gt;Products&lt;/a&gt;&lt;/li&gt;
                    736:   &lt;li&gt;&lt;a href="/about"&gt;About&lt;/a&gt;&lt;/li&gt;
                    737: &lt;/ul&gt;</pre>
                    738: 
                    739:    <p>The following example selects all the <code>li</code> elements and
1.108     lhunt     740:     demonstrates how to iterate through the collection in a <a
1.119     lhunt     741:     href="#nodelist"><code>NodeList</code></a>.
1.21      lhunt     742: 
1.41      lhunt     743:    <pre>var lis = document.querySelectorAll("ul.nav&gt;li");
1.24      lhunt     744: for (var i = 0; i &lt; lis.length; i++) {
1.21      lhunt     745:   process(lis.item(i));
                    746: }</pre>
                    747: 
1.108     lhunt     748:    <p>In ECMAScript, the language binding also allows <a
                    749:     href="#nodelist"><code>NodeList</code></a>s to be addressed using the
1.119     lhunt     750:     array notation, so that loop could be rewritten like this:
1.21      lhunt     751: 
1.24      lhunt     752:    <pre>for (var i = 0; i &lt; lis.length; i++) {
1.21      lhunt     753:   process(lis[i]);
                    754: }</pre>
                    755: 
1.108     lhunt     756:    <p>Since the <a href="#nodelist"><code>NodeList</code></a> objects
                    757:     returned by these methods are not live, changes to the DOM do not affect
                    758:     the content of the list. Consider the <code>process()</code> function
1.119     lhunt     759:     called in the previous examples is defined as follows:
1.21      lhunt     760: 
1.36      lhunt     761:    <pre>function process(elmt) {
1.21      lhunt     762:   elmt.parentNode.removeChild(elmt);
                    763: }</pre>
                    764: 
                    765:    <p>This would cause each selected element to be removed from the DOM, but
1.108     lhunt     766:     each element will remain in the <a
                    767:     href="#nodelist"><code>NodeList</code></a>. If the list were a live <a
                    768:     href="#nodelist"><code>NodeList</code></a>, removing an item from the DOM
                    769:     would also remove the element from the list and adjust the indexes of
                    770:     subsequent elements. That would have adverse effects upon the loop
1.119     lhunt     771:     because not all selected elements would be processed.
1.87      lhunt     772: 
                    773:    <p>In documents comprising elements from multiple namespaces, it's
                    774:     possible that some elements from different namespaces share the same
                    775:     local name. Since this API does not natively support a namespace
                    776:     resolution mechanism for selectors, obtaining a list of such elements
1.94      lhunt     777:     from a specific namespace, excluding all others, requires additional
1.87      lhunt     778:     processing to filter the result. The following example illustrates a
                    779:     document containing <code>video</code> elements from both the SVG and
1.119     lhunt     780:     XHTML namespaces.
1.87      lhunt     781: 
                    782:    <pre>&lt;svg id=&quot;svg1&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot;
                    783:                xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;
                    784:   &lt;video id=&quot;svgvideo1&quot; xlink:href=&quot;myvideo.ogg&quot; width=&quot;320&quot; height=&quot;240&quot;/&gt;
                    785:   &lt;foreignObject width=&quot;100&quot; height=&quot;100&quot;&gt;
                    786:     &lt;video id=&quot;htmlvideo1&quot; src=&quot;myvideo.ogg&quot; xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;No video1&lt;/video&gt;
                    787:   &lt;/foreignObject&gt;
                    788: &lt;/svg&gt;</pre>
                    789: 
                    790:    <p>The following script demonstrates how to first select the
                    791:     <code>video</code> elements and then filter out the unwanted elements
1.119     lhunt     792:     based on their namespace.
1.87      lhunt     793: 
1.106     lhunt     794:    <pre>var elms = document.querySelectorAll("svg video");
1.87      lhunt     795: var result = new Array();
                    796: var svgns = "http://www.w3.org/2000/svg"
                    797: 
1.122     lhunt     798: for(var i = 0; i &lt; elms.length; i++) {
1.107     lhunt     799:   if(elms[i].namespaceURI == svgns) {
1.87      lhunt     800:     result.push(elms[i]);
                    801:   }
                    802: }</pre>
1.21      lhunt     803:   </div>
                    804: 
1.11      avankest  805:   <h2 class=no-num id=references>References</h2>
1.1       avankest  806: 
1.54      lhunt     807:   <h3 class=no-num id=normative-references>Normative references</h3>
                    808:   <!--begin-normative-->
                    809:   <!-- Sorted by label -->
                    810: 
                    811:   <dl class=bibliography>
                    812:    <dt style="display: none"><!-- keeps the doc valid if the DL is empty -->
                    813:     <!---->
                    814: 
1.120     lhunt     815:    <dt id=DOM-BINDINGS>[DOM-BINDINGS]
                    816: 
                    817:    <dd>Cameron McCormack. <a
                    818:     href="http://www.w3.org/TR/2012/CR-WebIDL-20120419/"><cite>Web
                    819:     IDL.</cite></a> 19 April 2012. W3C Candidate Recommendation. (Work in
                    820:     progress.) URL: <a
                    821:     href="http://www.w3.org/TR/2012/CR-WebIDL-20120419/">http://www.w3.org/TR/2012/CR-WebIDL-20120419/</a>
                    822:    </dd>
                    823:    <!---->
                    824: 
1.54      lhunt     825:    <dt id=DOM-LEVEL-3-CORE>[DOM-LEVEL-3-CORE]
                    826: 
1.88      lhunt     827:    <dd>Gavin Nicol; et al. <a
1.54      lhunt     828:     href="http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407"><cite>Document
                    829:     Object Model (DOM) Level 3 Core Specification.</cite></a> 7 April 2004.
                    830:     W3C Recommendation. URL: <a
                    831:     href="http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407">http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407</a>
1.119     lhunt     832:    </dd>
1.54      lhunt     833:    <!---->
                    834: 
                    835:    <dt id=RFC2119>[RFC2119]
                    836: 
                    837:    <dd>S. Bradner. <a href="http://www.ietf.org/rfc/rfc2119.txt"><cite>Key
                    838:     words for use in RFCs to Indicate Requirement Levels.</cite></a> Internet
                    839:     RFC 2119. URL: <a
                    840:     href="http://www.ietf.org/rfc/rfc2119.txt">http://www.ietf.org/rfc/rfc2119.txt</a>
1.119     lhunt     841:    </dd>
1.54      lhunt     842:    <!---->
                    843: 
                    844:    <dt id=SELECT>[SELECT]
                    845: 
1.108     lhunt     846:    <dd>Tantek Çelik; et al. <a
1.107     lhunt     847:     href="http://www.w3.org/TR/2011/REC-css3-selectors-20110929/"><cite>Selectors
                    848:     Level 3.</cite></a> 29 September 2011. W3C Recommendation. URL: <a
                    849:     href="http://www.w3.org/TR/2011/REC-css3-selectors-20110929/">http://www.w3.org/TR/2011/REC-css3-selectors-20110929/</a>
1.119     lhunt     850:    </dd>
1.54      lhunt     851:    <!---->
                    852:   </dl>
                    853:   <!--end-normative-->
1.1       avankest  854: 
1.84      lhunt     855:   <h3 class=no-num id=informative-references>Informative references</h3>
1.54      lhunt     856:   <!--begin-informative-->
                    857:   <!-- Sorted by label -->
                    858: 
                    859:   <dl class=bibliography>
                    860:    <dt style="display: none"><!-- keeps the doc valid if the DL is empty -->
                    861:     <!---->
                    862: 
1.69      lhunt     863:    <dt id=CSS21>[CSS21]
                    864: 
                    865:    <dd>Bert Bos; et al. <a
1.125     lhunt     866:     href="http://www.w3.org/TR/2011/REC-CSS2-20110607/"><cite>Cascading Style
1.108     lhunt     867:     Sheets Level 2 Revision 1 (CSS 2.1) Specification.</cite></a> 7 June
1.106     lhunt     868:     2011. W3C Recommendation. URL: <a
1.125     lhunt     869:     href="http://www.w3.org/TR/2011/REC-CSS2-20110607/">http://www.w3.org/TR/2011/REC-CSS2-20110607/</a>
1.119     lhunt     870:    </dd>
1.69      lhunt     871:    <!---->
                    872: 
1.54      lhunt     873:    <dt id=DOM-LEVEL-2-STYLE>[DOM-LEVEL-2-STYLE]
                    874: 
1.108     lhunt     875:    <dd>Chris Wilson; Philippe Le Hégaret; Vidur Apparao. <a
1.125     lhunt     876:     href="http://www.w3.org/TR/2000/REC-DOM-Level-2-Style-20001113/"><cite>Document
1.54      lhunt     877:     Object Model (DOM) Level 2 Style Specification.</cite></a> 13 November
                    878:     2000. W3C Recommendation. URL: <a
1.125     lhunt     879:     href="http://www.w3.org/TR/2000/REC-DOM-Level-2-Style-20001113/">http://www.w3.org/TR/2000/REC-DOM-Level-2-Style-20001113/</a>
1.119     lhunt     880:    </dd>
1.54      lhunt     881:    <!---->
                    882: 
1.121     lhunt     883:    <dt id=ECMA-262-5.1>[ECMA-262-5.1]
1.54      lhunt     884: 
                    885:    <dd><a
                    886:     href="http://www.ecma-international.org/publications/standards/Ecma-262.htm"><cite>ECMAScript
1.121     lhunt     887:     Language Specification, Edition 5.1.</cite></a> June 2011. ISO/IEC
                    888:     16262:2011. URL: <a
1.54      lhunt     889:     href="http://www.ecma-international.org/publications/standards/Ecma-262.htm">http://www.ecma-international.org/publications/standards/Ecma-262.htm</a>
1.119     lhunt     890:    </dd>
1.54      lhunt     891:    <!---->
1.1       avankest  892:   </dl>
1.54      lhunt     893:   <!--end-informative-->
1.1       avankest  894: 
1.11      avankest  895:   <h2 class=no-num id=acknowledgements>Acknowledgements</h2>
1.1       avankest  896: 
1.45      avankest  897:   <p>The editors would like to thank to the following people who have
1.7       avankest  898:    contributed to this specification (ordered on first name):
                    899: 
1.124     lhunt     900:   <p>Adam van den Hoven, Alan Gresley, Alex Russell, Arthur Barstow, Aryeh
                    901:    Gregor, Björn Höhrmann, Boris Zbarsky, Cameron McCormack, Charles
                    902:    McCathieNevile, Chris Wilson, Christophe Jolif, Daniel Glazman, Daniel
                    903:    Schierbeck, Dave Massy, David "liorean" Andersson, David Greenspan, David
                    904:    Håsäther, Dean Jackson, Doug Schepers, Erik Dahlström, Francois Remy,
                    905:    Hallvord R. M. Steen, Henri Sivonen, Ian Hickson, Ivan Enderlin, Jean-Yves
                    906:    Bitterlich, Jim Ley, João Eiras, John Resig, Jon Ferraiolo, Jonas
                    907:    Sicking, Jorgen Horstink, Kang-Hao (Kenny) Lu, Karl Dubost, Kartikaya
                    908:    Gupta, L. David Baron, Maciej Stachowiak, Magnus Kristiansen, Marat
                    909:    Tanalin, Martijn, Masataka Yakura, Mihai Sucan, Mohamed Zergaoui, Nicholas
                    910:    C. Zakas, Nicolas Mendoza, Norbert Lindenberg, Philip Taylor, Robert
                    911:    Sayre, Robin Berjon, Sander, Sergey Ilinsky, Simon Pieters, Steven
                    912:    Pemberton, Stewart Brodie Tab Atkins Jr., Tarquin Wilton-Jones, Travis
                    913:    Leithead, and William J. Edney
1.1       avankest  914: 
1.126     lhunt     915:   <p>Special thanks to John Resig and Øyvind Stenhaug for their significant
                    916:    contributions to the testsuite.
                    917: 
1.1       avankest  918:   <p>Thanks to all those who have helped to improve this specification by
1.96      lhunt     919:    sending suggestions and corrections.

Webmaster