Skip to content

Commit fd69cc7

Browse files
committed
Add Element.prototype.closest(selectors)
1 parent 39c2927 commit fd69cc7

File tree

2 files changed

+60
-14
lines changed

2 files changed

+60
-14
lines changed

Overview.src.html

+29-6
Original file line numberDiff line numberDiff line change
@@ -5232,7 +5232,8 @@ <h3>Interface <code>Element</code></h3>
52325232
<span>Attr</span> <span title=dom-Element-setAttributeNode>setAttributeNode</span>(Attr newAttr);
52335233
<span>Attr</span> <span title=dom-Element-removeAttributeNode>removeAttributeNode</span>(Attr oldAttr);
52345234
-->
5235-
boolean <span title=dom-Element-matches>matches</span>(DOMString <var title>selectors</var>);
5235+
<span>Element</span>? <span title=dom-Element-closest>closest</span>(DOMString <var>selectors</var>);
5236+
boolean <span title=dom-Element-matches>matches</span>(DOMString <var>selectors</var>);
52365237

52375238
<span>HTMLCollection</span> <span title=dom-Element-getElementsByTagName>getElementsByTagName</span>(DOMString <var title>localName</var>);
52385239
<span>HTMLCollection</span> <span title=dom-Element-getElementsByTagNameNS>getElementsByTagNameNS</span>(DOMString? <var title>namespace</var>, DOMString <var title>localName</var>);
@@ -5774,18 +5775,23 @@ <h3>Interface <code>Element</code></h3>
57745775
<hr>
57755776

57765777
<dl class=domintro>
5777-
<dt><code><var title>element</var> . <span title=dom-Element-matches>matches</span>(<var title>selectors</var>)</code>
5778-
<dd><p>Returns true if matching <var title>selectors</var> against
5778+
<dt><code><var title>element</var> . <span title=dom-Element-closest>closest</span>(<var>selectors</var>)</code>
5779+
<dd><p>Returns the first (starting at <var title>element</var>)
5780+
<span title=concept-tree-inclusive-ancestor>inclusive ancestor</span> that matches
5781+
<var title>selectors</var>, and null otherwise.
5782+
5783+
<dt><code><var title>element</var> . <span title=dom-Element-matches>matches</span>(<var>selectors</var>)</code>
5784+
<dd><p>Returns true if matching <var>selectors</var> against
57795785
<var title>element</var>'s <span title=concept-tree-root>root</span> yields
57805786
<var title>element</var>, and false otherwise.
57815787
</dl>
57825788

5783-
<p>To <dfn>match a selectors string</dfn> <var title>selectors</var> against a
5789+
<p>To <dfn>match a selectors string</dfn> <var>selectors</var> against a
57845790
<var title>set</var>, run these steps:
57855791

57865792
<ol>
57875793
<li><p>Let <var title>s</var> be the result of
5788-
<span data-anolis-spec=selectors>parse a selector</span> from <var title>selectors</var>.
5794+
<span data-anolis-spec=selectors>parse a selector</span> from <var>selectors</var>.
57895795
<span data-anolis-ref>SELECTORS</span>
57905796

57915797
<li><p>If <var title>s</var> is failure, <span title=concept-throw>throw</span> a
@@ -5797,9 +5803,26 @@ <h3>Interface <code>Element</code></h3>
57975803
<var title>set</var>. <span data-anolis-ref>SELECTORS</span>
57985804
</ol>
57995805

5806+
<p>The <dfn title=dom-Element-closest><code>closest(<var>selectors</var>)</code></dfn>
5807+
method must run these steps:
5808+
5809+
<ol>
5810+
<li><p>Let <var>elements</var> be <span>context object</span>'s
5811+
<span title=concept-tree-inclusive-ancestor>inclusive ancestor</span> that are
5812+
<span title=concept-element>elements</span>, in reverse
5813+
<span title=concept-tree-order>tree order</span>.
5814+
5815+
<li><p>For each <var title>element</var> in <var>elements</var>, return
5816+
<var title>element</var> if <var title>element</var> is in the result of running
5817+
<span>match a selectors string</span> <var>selectors</var> against a set consisting
5818+
of <var title>element</var>.
5819+
5820+
<li><p>Return null.
5821+
</ol>
5822+
58005823
<p>The <dfn title=dom-Element-matches><code>matches(<var>selectors</var>)</code></dfn>
58015824
method must return true if the <span>context object</span> is in the result of running
5802-
<span>match a selectors string</span> <var title>selectors</var> against a set consisting
5825+
<span>match a selectors string</span> <var>selectors</var> against a set consisting
58035826
of <span>context object</span>, and false otherwise.
58045827

58055828
<hr>

dom-core.html

+31-8
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
<hgroup>
1111
<h1 class="allcaps">DOM</h1>
12-
<h2>Living Standard — Last Updated 22 May 2014</h2>
12+
<h2>Living Standard — Last Updated 26 May 2014</h2>
1313
</hgroup>
1414

1515
<dl>
@@ -44,7 +44,7 @@ <h2>Living Standard — Last Updated 22 May 2014</h2>
4444
<p class="copyright"><a href="http://creativecommons.org/publicdomain/zero/1.0/" rel="license"><img alt="CC0" src="http://i.creativecommons.org/p/zero/1.0/80x15.png"></a>
4545
To the extent possible under law, the editors have waived all copyright and
4646
related or neighboring rights to this work. In addition, as of
47-
22 May 2014, the editors have made this specification available
47+
26 May 2014, the editors have made this specification available
4848
under the
4949
<a href="http://www.openwebfoundation.org/legal/the-owf-1-0-agreements/owfa-1-0" rel="license">Open Web Foundation Agreement Version 1.0</a>,
5050
which is available at
@@ -5306,7 +5306,8 @@ <h3 id="interface-element"><span class="secno">5.8 </span>Interface <code><a hre
53065306
<span>Attr</span> <span title=dom-Element-setAttributeNode>setAttributeNode</span>(Attr newAttr);
53075307
<span>Attr</span> <span title=dom-Element-removeAttributeNode>removeAttributeNode</span>(Attr oldAttr);
53085308
-->
5309-
boolean <a href="#dom-element-matches" title="dom-Element-matches">matches</a>(DOMString <var title="">selectors</var>);
5309+
<a href="#element">Element</a>? <a href="#dom-element-closest" title="dom-Element-closest">closest</a>(DOMString <var>selectors</var>);
5310+
boolean <a href="#dom-element-matches" title="dom-Element-matches">matches</a>(DOMString <var>selectors</var>);
53105311

53115312
<a href="#htmlcollection">HTMLCollection</a> <a href="#dom-element-getelementsbytagname" title="dom-Element-getElementsByTagName">getElementsByTagName</a>(DOMString <var title="">localName</var>);
53125313
<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>);
@@ -5848,18 +5849,23 @@ <h3 id="interface-element"><span class="secno">5.8 </span>Interface <code><a hre
58485849
<hr>
58495850

58505851
<dl class="domintro">
5851-
<dt><code><var title="">element</var> . <a href="#dom-element-matches" title="dom-Element-matches">matches</a>(<var title="">selectors</var>)</code>
5852-
<dd><p>Returns true if matching <var title="">selectors</var> against
5852+
<dt><code><var title="">element</var> . <a href="#dom-element-closest" title="dom-Element-closest">closest</a>(<var>selectors</var>)</code>
5853+
<dd><p>Returns the first (starting at <var title="">element</var>)
5854+
<a href="#concept-tree-inclusive-ancestor" title="concept-tree-inclusive-ancestor">inclusive ancestor</a> that matches
5855+
<var title="">selectors</var>, and null otherwise.
5856+
5857+
<dt><code><var title="">element</var> . <a href="#dom-element-matches" title="dom-Element-matches">matches</a>(<var>selectors</var>)</code>
5858+
<dd><p>Returns true if matching <var>selectors</var> against
58535859
<var title="">element</var>'s <a href="#concept-tree-root" title="concept-tree-root">root</a> yields
58545860
<var title="">element</var>, and false otherwise.
58555861
</dl>
58565862

5857-
<p>To <dfn id="match-a-selectors-string">match a selectors string</dfn> <var title="">selectors</var> against a
5863+
<p>To <dfn id="match-a-selectors-string">match a selectors string</dfn> <var>selectors</var> against a
58585864
<var title="">set</var>, run these steps:
58595865

58605866
<ol>
58615867
<li><p>Let <var title="">s</var> be the result of
5862-
<a class="external" data-anolis-spec="selectors" href="http://dev.w3.org/csswg/selectors/#parse-a-selector">parse a selector</a> from <var title="">selectors</var>.
5868+
<a class="external" data-anolis-spec="selectors" href="http://dev.w3.org/csswg/selectors/#parse-a-selector">parse a selector</a> from <var>selectors</var>.
58635869
<a href="#refsSELECTORS">[SELECTORS]</a>
58645870

58655871
<li><p>If <var title="">s</var> is failure, <a href="#concept-throw" title="concept-throw">throw</a> a
@@ -5871,9 +5877,26 @@ <h3 id="interface-element"><span class="secno">5.8 </span>Interface <code><a hre
58715877
<var title="">set</var>. <a href="#refsSELECTORS">[SELECTORS]</a>
58725878
</ol>
58735879

5880+
<p>The <dfn id="dom-element-closest" title="dom-Element-closest"><code>closest(<var>selectors</var>)</code></dfn>
5881+
method must run these steps:
5882+
5883+
<ol>
5884+
<li><p>Let <var><a href="#elements">elements</a></var> be <a href="#context-object">context object</a>'s
5885+
<a href="#concept-tree-inclusive-ancestor" title="concept-tree-inclusive-ancestor">inclusive ancestor</a> that are
5886+
<a href="#concept-element" title="concept-element">elements</a>, in reverse
5887+
<a href="#concept-tree-order" title="concept-tree-order">tree order</a>.
5888+
5889+
<li><p>For each <var title="">element</var> in <var><a href="#elements">elements</a></var>, return
5890+
<var title="">element</var> if <var title="">element</var> is in the result of running
5891+
<a href="#match-a-selectors-string">match a selectors string</a> <var>selectors</var> against a set consisting
5892+
of <var title="">element</var>.
5893+
5894+
<li><p>Return null.
5895+
</ol>
5896+
58745897
<p>The <dfn id="dom-element-matches" title="dom-Element-matches"><code>matches(<var>selectors</var>)</code></dfn>
58755898
method must return true if the <a href="#context-object">context object</a> is in the result of running
5876-
<a href="#match-a-selectors-string">match a selectors string</a> <var title="">selectors</var> against a set consisting
5899+
<a href="#match-a-selectors-string">match a selectors string</a> <var>selectors</var> against a set consisting
58775900
of <a href="#context-object">context object</a>, and false otherwise.
58785901

58795902
<hr>

0 commit comments

Comments
 (0)