-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Expand file tree
/
Copy pathhas-with-is-child-combinator.html
More file actions
64 lines (56 loc) · 2.07 KB
/
has-with-is-child-combinator.html
File metadata and controls
64 lines (56 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<!DOCTYPE html>
<meta charset="utf-8">
<title>CSS Selector Invalidation: :has(> :is()) with child combinator</title>
<link rel="author" title="Nipun Shukla" href="mailto:nipun_shukla@apple.com">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<link rel="help" href="https://un5n798jx6qx6j0rmf2verhh.julianrbryant.com/selectors/#relational">
<style>
div, main { color: grey }
#subject:has(> :is(.parent > .child)) { color: green }
#subject:has(> :is(.parent .descendant)) { color: blue }
#subject:has(:is(.deep-parent > .deep-child)) { color: red }
</style>
<main id=main>
<div id=subject>
<div id=direct_child>
<div id=grandchild></div>
</div>
</div>
</main>
<script>
const grey = 'rgb(128, 128, 128)';
const green = 'rgb(0, 128, 0)';
const blue = 'rgb(0, 0, 255)';
const red = 'rgb(255, 0, 0)';
function testColor(test_name, color) {
test(function() {
assert_equals(getComputedStyle(subject).color, color);
}, test_name);
}
testColor('Initial color', grey);
// :has(> :is(.parent > .child))
subject.classList.add('parent');
testColor('add .parent to subject', grey);
direct_child.classList.add('child');
testColor('add .child to direct_child', green);
direct_child.classList.remove('child');
testColor('remove .child from direct_child', grey);
subject.classList.remove('parent');
// :has(> :is(.parent .descendant))
subject.classList.add('parent');
testColor('add .parent to subject for .descendant test', grey);
direct_child.classList.add('descendant');
testColor('add .descendant to direct_child', blue);
direct_child.classList.remove('descendant');
testColor('remove .descendant from direct_child', grey);
subject.classList.remove('parent');
// :has(:is(.deep-parent > .deep-child))
grandchild.classList.add('deep-child');
testColor('add .deep-child to grandchild', grey);
direct_child.classList.add('deep-parent');
testColor('add .deep-parent to direct_child', red);
direct_child.classList.remove('deep-parent');
testColor('remove .deep-parent from direct_child', grey);
grandchild.classList.remove('deep-child');
</script>