@@ -151,9 +151,9 @@ Selectors Overview</h2>
151
151
<tr>
152
152
<td><code> E:has(<var> rs1</var> , <var> rs2</var> , …)</code>
153
153
<td> an E element,
154
- if either of the <a>relative selectors</a> <var> rs1 </var> or <var> rs2 </var> ,
155
- when evaluated with E as the <a>:scope elements </a> ,
156
- match an element
154
+ if there exists an element that matches
155
+ either of the <a>relative selectors </a> <var> rs1 </var> or <var> rs2 </var > ,
156
+ when evaluated with E as the <a>anchor elements</a>
157
157
<td> [[#relational]]
158
158
<td> 4
159
159
<tbody>
@@ -272,7 +272,7 @@ Selectors Overview</h2>
272
272
<td> 4
273
273
<tr>
274
274
<td><code> E:scope</code>
275
- <td> an E element being a designated reference element
275
+ <td> an E element being a [=scoping root=]
276
276
<td> [[#the-scope-pseudo]]
277
277
<td> 4
278
278
<tbody>
@@ -502,7 +502,7 @@ Structure and Terminology</h3>
502
502
a particular pattern of element(s) in a tree structure.
503
503
The term <a>selector</a> can refer to a <a>simple selector</a> ,
504
504
<a>compound selector</a> , <a>complex selector</a> , or <a>selector list</a> .
505
- The <dfn export for=selector lt="subject|subject of a selector">subject of a selector</dfn> is
505
+ The <dfn export for=selector lt="subject|subject of a selector|subject of the selector ">subject of a selector</dfn> is
506
506
any element that selector is defined to be about;
507
507
that is, any element <dfn export lt="match">matching</dfn> that <a>selector</a> .
508
508
@@ -636,10 +636,8 @@ Data Model</h3>
636
636
Scoped Selectors</h3>
637
637
638
638
Some host applications may choose to <dfn export lt="scoped selector" local-lt="scope">scope</dfn> selectors
639
- to a particular subtree or fragment of the document.
640
- The root of the scoping subtree is called the <dfn export>scoping root</dfn> ,
641
- and may be either a true element (the <dfn export>scoping element</dfn> )
642
- or a <dfn export lt="virtual scoping root">virtual</dfn> one (such as a <a interface>DocumentFragment</a> ).
639
+ to a particular subtree or fragment of the document,
640
+ The root of the scoping subtree is called the <dfn export>scoping root</dfn> .
643
641
644
642
When a selector is <a>scoped</a> ,
645
643
it matches an element only if the element is a descendant of the <a>scoping root</a> .
@@ -648,83 +646,31 @@ Scoped Selectors</h3>
648
646
649
647
<div class='example'>
650
648
For example,
651
- the <code> element. querySelector()</code> function defined in [[DOM]]
649
+ the {{Element/ querySelector()}} method defined in [[DOM]]
652
650
allows the author to evaluate a <a>scoped</a> selector
653
- relative to the <code> element</code> it's called on.
651
+ relative to the element it's called on.
654
652
655
653
A call like <code highlight=js> widget.querySelector("a")</code>
656
654
will thus only find <{a}> elements inside of the <code> widget</code> element,
657
655
ignoring any other <{a}> s that might be scattered throughout the document.
658
656
</div>
659
657
660
- Note: If the context does not explicitly define any <a>:scope elements</a> for the selector,
661
- the <a>scoping root</a> is the <a>:scope element</a> .
662
658
663
659
<h3 id="relative">
664
660
Relative Selectors</h3>
665
661
666
- Certain contexts may accept <dfn lt="relative selector | relative | scope-relative" export>relative selectors</dfn> ,
667
- which are a shorthand for selectors that represent elements relative to a <a>:scope element</a>
668
- (i.e. an element that matches '':scope'' ).
669
- In a <a>relative selector</a> ,
670
- “:scope ” (the '':scope'' pseudo-class followed by a space)
671
- is implied at the beginning of each <a>complex selector</a>
672
- that does not already contain the '':scope'' pseudo-class.
673
- This allows the selector to begin syntactically with a <a>combinator</a> .
674
- However, it must be <a href="#absolutize">absolutized</a> before matching.
662
+ Certain contexts may accept <dfn lt="relative selector" local-lt="relative" export>relative selectors</dfn> ,
663
+ which are a shorthand for selectors that represent elements relative to one or more
664
+ <dfn export local-lt="anchor element">relative selector anchor elements</dfn> .
665
+ Relative selectors begin with a <a>combinator</a> ,
666
+ with a selector representing the [=anchor element=]
667
+ implied at the start of the selector.
668
+ (If no combinator is present,
669
+ the [=descendant combinator=] is implied.)
675
670
676
- Relative selectors, once absolutized ,
677
- can additionally be <a>scoped</a > .
671
+ Relative selectors are represented by <<relative-selector>> in the selectors <a href="#grammar">grammar</a> ,
672
+ and lists of them by <<relative-selector-list> > .
678
673
679
- Relative selectors are represented by <<relative-selector>> in the selectors <a href="#grammar">grammar</a> .
680
-
681
- <h4 id='absolutizing'>
682
- Absolutizing a Relative Selector</h4>
683
-
684
- To <dfn id='absolutize' export>absolutize a relative selector</dfn> :
685
-
686
- If there are no <a>:scope elements</a>
687
- and the selector is <a>scoped</a> to a <a>virtual scoping root</a> :
688
-
689
- ISSUE: <a href="https://github.com/w3c/csswg-drafts/issues/2199">This needs a sane definition.</a>
690
-
691
- <!--
692
- <ol>
693
- <li>
694
- If the selector starts with a <a>child combinator</a> ,
695
- remove the child combinator.
696
- The selector is now absolute,
697
- with the additional constraint that the first compound selector in the selector
698
- only matches elements without a parent.
699
-
700
- <li>
701
- Otherwise, if the selector starts with any combinator other than the white space form of the <a>descendant combinator</a> ,
702
- change the selector to '':not(*)'' .
703
- <span class='note'> This is the shortest selector that is valid, but guaranteed to match nothing.</span>
704
-
705
- <li>
706
- Otherwise, the selector is already absolute.
707
- </ol>
708
- -->
709
-
710
- Otherwise:
711
-
712
- <ol>
713
- <li>
714
- If the selector starts with a <a>combinator</a> other than the white space form of the <a>descendant combinator</a> ,
715
- prepend '':scope'' as the initial <a>compound selector</a> .
716
-
717
- <li>
718
- Otherwise, if the selector does not contain any instance of the '':scope'' pseudo-class
719
- (either at the top-level or as an argument to a functional pseudo-class),
720
- prepend '':scope'' followed by the white space form of the <a>descendant combinator</a> .
721
-
722
- <li>
723
- Otherwise, the selector is already absolute.
724
- </ol>
725
-
726
- To <dfn id='absolutize-list' export>absolutize a relative selector list</dfn> ,
727
- absolutize each relative selector in the list.
728
674
729
675
730
676
<h3 id="pseudo-classes">
@@ -1244,10 +1190,9 @@ The Relational Pseudo-class: '':has()''</h3>
1244
1190
1245
1191
The relational pseudo-class, <dfn id='has-pseudo'>:has()</dfn> ,
1246
1192
is a functional pseudo-class taking a <<forgiving-relative-selector-list>> as an argument.
1247
- It represents an element if any of the <a>relative selectors</a> ,
1248
- when <a href="#absolutize">absolutized</a>
1249
- and evaluated with the element as the <a>:scope elements</a> ,
1250
- would match at least one element.
1193
+ It represents an element if any of the <a>relative selectors</a>
1194
+ would match at least one element
1195
+ when [=anchor element|anchored against=] this element.
1251
1196
1252
1197
<div class='example'>
1253
1198
For example, the following selector matches only
@@ -1274,8 +1219,6 @@ The Relational Pseudo-class: '':has()''</h3>
1274
1219
which contains anything that's not a heading element.
1275
1220
</div>
1276
1221
1277
- Supporting the '':has()'' pseudo-class is not required to conform to this specification.
1278
-
1279
1222
1280
1223
<h2 id="elemental-selectors">
1281
1224
Elemental selectors</h2>
@@ -2159,20 +2102,37 @@ The Target Container Pseudo-class: '':target-within''</h3>
2159
2102
<h3 id="the-scope-pseudo">
2160
2103
The Reference Element Pseudo-class: '':scope''</h3>
2161
2104
2162
- In some contexts, selectors can be matched with an explicit set of <dfn dfn export lt=":scope element">:scope elements</dfn> .
2163
- This is a (potentially empty) set of elements
2164
- that provide a reference point for selectors to match against,
2165
- such as that specified by the <code> querySelector()</code> call in [[DOM]] .
2105
+ In some contexts, selectors are matched
2106
+ with respect to one or more [=scoping roots=] ,
2107
+ such as when calling the {{Element/querySelector()}} method in [[DOM]] .
2108
+ The <dfn id='scope-pseudo'>:scope</dfn> pseudo-class represents
2109
+ this [=scoping root=] ,
2110
+ and may be either a true element
2111
+ or a virtual one (such as a {{DocumentFragment}} ).
2166
2112
2167
- The <dfn id='scope-pseudo'>:scope</dfn> pseudo-class represents any element that is a <a>:scope element</a> .
2168
- If the <a>:scope elements</a> are not explicitly specified,
2169
- but the selector is <a>scoped</a> and the <a>scoping root</a> is an element,
2170
- then '':scope'' represents the <a>scoping root</a> ;
2171
- otherwise, it represents the root of the document
2113
+ If there is no [=scoping root=]
2114
+ then '':scope'' represents the root of the document
2172
2115
(equivalent to '':root'' ).
2173
2116
Specifications intending for this pseudo-class to match specific elements
2174
2117
rather than the document's root element
2175
- must define either a <a>scoping root</a> (if using <a>scoped selectors</a> ) or an explicit set of <a>:scope elements</a> .
2118
+ must define their [=scoping root|scoping root(s)=] .
2119
+
2120
+ A virtual [=scoping root=] is some object representing the root of a document fragment,
2121
+ and can be used in selector patterns to represent other elements’ relationships
2122
+ to this [=scoping root=] ,
2123
+ acting as the parent of any root elements in the document fragment it represents.
2124
+ A virtual [=scoping root=] is [=featureless=]
2125
+ and cannot be the [=subject of the selector=] .
2126
+
2127
+ <div class=example>
2128
+ For example, if you have a {{DocumentFragment}} <code> df</code> ,
2129
+ then <code highlight=js> df.querySelectorAll(":scope > .foo")</code>
2130
+ matches all the ''.foo'' elements that are "top-level" in the document fragment
2131
+ (those that have the document fragment as their {{Node/parentNode}} ).
2132
+
2133
+ However, <code highlight=js> df.querySelector(":scope")</code> will not match anything,
2134
+ as the document fragment itself can't be the [=subject of the selector=] .
2135
+ </div>
2176
2136
2177
2137
<h2 id="useraction-pseudos">
2178
2138
User Action Pseudo-classes</h2>
@@ -3678,30 +3638,25 @@ Parse A Selector</h3>
3678
3638
<h3 id='parse-relative-selector' algorithm>
3679
3639
Parse A Relative Selector</h3>
3680
3640
3681
- This section defines how to <dfn export>parse a relative selector</dfn> from a string <var> source</var> ,
3682
- against <a>:scope elements</a> <var> refs</var> .
3641
+ This section defines how to <dfn export>parse a relative selector</dfn> from a string <var> source</var> .
3683
3642
It returns either a complex selector list,
3684
3643
or failure.
3685
3644
3686
3645
<ol>
3687
3646
<li>
3688
3647
Let <var> selector</var> be the result of [=CSS/parsing=] <var> source</var> as a <<relative-selector-list>> .
3689
- If this return failure,
3648
+ If this returns failure,
3649
+ it's an [=invalid selector=] ;
3690
3650
return failure.
3691
3651
3692
3652
<li>
3693
- Otherwise,
3694
- if any simple selectors in <var> selector</var> are not recognized by the user agent,
3695
- or <var> selector</var> is otherwise invalid in some way
3653
+ If |selector| is an [=invalid selector=] for any other reason
3696
3654
(such as, for example, containing an undeclared namespace prefix),
3697
3655
return failure.
3698
3656
3699
3657
<li>
3700
3658
Otherwise,
3701
- <a lt="absolutize a relative selector list">absolutize <var>selector</var></a> with <var> refs</var> as the <a>:scope elements</a> .
3702
-
3703
- <li>
3704
- Return <var> selector</var> .
3659
+ return <var> selector</var> .
3705
3660
</ol>
3706
3661
3707
3662
<h3 id='match-against-element' algorithm>
@@ -3715,16 +3670,8 @@ Match a Selector Against an Element</h3>
3715
3670
3716
3671
<ul>
3717
3672
<li>
3718
- a set of <a>:scope elements</a> ,
3673
+ one or more [=scoping roots=] ,
3719
3674
for resolving the '':scope'' pseudo-class against.
3720
- If not specified,
3721
- the set defaults to being empty.
3722
-
3723
- Issue: Should it instead default to the root element,
3724
- to match the definition of '':scope'' ?
3725
-
3726
- If the selector is a <a>relative selector</a> ,
3727
- the set of <a>:scope elements</a> must not be empty.
3728
3675
</ul>
3729
3676
3730
3677
This algorithm returns either success or failure.
@@ -3794,47 +3741,28 @@ Match a Selector Against a Tree</h3>
3794
3741
3795
3742
APIs using this algorithm must provide a selector,
3796
3743
and one or more <var> root elements</var>
3797
- indicating the <a>trees</a> that will be searched by the selector.
3798
- All of the <var> root elements</var> must share the same <a for =tree>root</a> ,
3744
+ indicating the [=tree|subtrees=] that will be searched by the selector.
3745
+ All of the <var> root elements</var> must share the same [ =tree/root=] ,
3799
3746
or else calling this algorithm is invalid.
3800
3747
3801
3748
They may optionally provide:
3802
3749
3803
3750
<ul>
3804
3751
<li>
3805
- A <a>scoping root </a>
3752
+ One or more <a>scoping roots </a>
3806
3753
indicating the selector is <a>scoped</a> .
3807
- If not specified,
3808
- the <var> selector</var> defaults to being unscoped.
3809
-
3810
- Issue: This is now redundant with the <var> root elements</var> .
3811
-
3812
- <li>
3813
- A set of <a>:scope elements</a> ,
3814
- which will match the '':scope'' pseudo-class.
3815
- If not specified,
3816
- then if the selector is a <a>scoped selector</a> ,
3817
- the set of <a>:scope elements</a> default to the <a>scoping root</a> ;
3818
- otherwise,
3819
- it defaults to the <var> root elements</var> .
3820
-
3821
- Note: Note that if the selector is scoped,
3822
- the scoping root is automatically taken as the <a>:scope element</a> ,
3823
- so it doesn't have to be provided explicitly
3824
- unless a different result is desired.
3825
3754
3826
3755
<li>
3827
- Which <a>pseudo-elements</a> are allowed to show up in the match list.
3756
+ A list of <a>pseudo-elements</a> that are allowed to show up in the match list.
3828
3757
If not specified, this defaults to allowing all pseudo-elements.
3829
3758
3830
- Issue: Only the ''::before'' and ''::after'' pseudo-elements are really
3759
+ Issue: Only the [=tree-abiding pseudo-elements=] are really
3831
3760
handled in any way remotely like this.
3832
3761
</ul>
3833
3762
3834
3763
This algorithm returns a (possibly empty) list of elements.
3835
3764
3836
3765
<ol>
3837
-
3838
3766
<li>
3839
3767
Start with a list of <var> candidate elements</var> ,
3840
3768
which are the <var> root elements</var>
@@ -3843,10 +3771,10 @@ Match a Selector Against a Tree</h3>
3843
3771
unless otherwise specified.
3844
3772
3845
3773
<li>
3846
- If an optional scoping root was provided,
3774
+ If [= scoping root=] were provided,
3847
3775
then remove from the <var> candidate elements</var>
3848
3776
any elements that are not
3849
- <a>descendants</a> of the <a>scoping root</a> .
3777
+ <a>descendants</a> of at least one <a>scoping root</a> .
3850
3778
3851
3779
<li>
3852
3780
Initialize the <var> selector match list</var> to empty.
@@ -4057,6 +3985,18 @@ Appendix B: Obsolete but Required Parsing Quirks for Web Compat</h2>
4057
3985
4058
3986
<h2 id="changes">
4059
3987
Changes</h2>
3988
+
3989
+ <h3 id="changes-2022-05">
3990
+ Changes since the 7 May 2022 Working Draft</h3>
3991
+
3992
+ Significant changes since the <a href="https://www.w3.org/TR/2022/WD-selectors-4-20220507/">7 May 2022 Working Draft</a> :
3993
+
3994
+ * Untangled the concepts of "scoped" and "relative" selectors completely.
3995
+ (<a href="https://github.com/w3c/csswg-drafts/issues/6399">Issue 6399</a> )
3996
+ * Removed "absolutize a selector" as well,
3997
+ and just defined relative selector matching
3998
+ in terms of the anchoring element.
3999
+
4060
4000
<h3 id="changes-2018-11">
4061
4001
Changes since the 21 November 2018 Working Draft</h3>
4062
4002
0 commit comments