Source code
Revision control
Copy as Markdown
Other Tools
<!DOCTYPE html>
<meta charset="utf-8">
<title>CSS Selector Invalidation: multiple rules sharing the same :has() argument</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<style>
.a, .b { color: grey; }
#anchor:has(:is(.x .y)) .a { color: green; }
#anchor:has(:is(.x .y)) .b { color: green; }
</style>
<div id="anchor">
<div class="a" id="a"></div>
<div class="b" id="b"></div>
<div id="container"><div class="y"></div></div>
</div>
<script>
const grey = "rgb(128, 128, 128)";
const green = "rgb(0, 128, 0)";
function assert_colors(expected) {
assert_equals(getComputedStyle(a).color, expected, ".a");
assert_equals(getComputedStyle(b).color, expected, ".b");
}
test(() => {
assert_colors(grey);
container.classList.add("x");
assert_colors(green);
container.classList.remove("x");
assert_colors(grey);
}, "Class change invalidates all rules sharing the :has() argument");
test(() => {
const x = document.createElement("div");
x.className = "x";
x.innerHTML = '<div class="y"></div>';
anchor.appendChild(x);
assert_colors(green);
x.remove();
assert_colors(grey);
}, "Insertion and removal invalidate all rules sharing the :has() argument");
</script>