link-pseudo-class-in-has.html (2044B)
1 <!DOCTYPE html> 2 <meta charset="utf-8" /> 3 <title>CSS Selectors Invalidation: :any-link and :link pseudo class in :has()</title> 4 <link rel="author" title="Tim Nguyen" href="https://github.com/nt1m"> 5 <link rel="help" href="https://drafts.csswg.org/selectors/#relational"> 6 7 <script src="/resources/testharness.js"></script> 8 <script src="/resources/testharnessreport.js"></script> 9 <script src="/resources/testdriver.js"></script> 10 <script src="/resources/testdriver-vendor.js"></script> 11 12 <style> 13 /* :any-link and :link should match similarly */ 14 #subject:has(#target:link:any-link) { color: green; } 15 #subject:has(#svgTarget:link:any-link) { color: blue; } 16 </style> 17 18 <div id="subject"> 19 This is some text. 20 <a id="target">This is an anchor element</a> 21 <svg xmlns="http://www.w3.org/2000/svg"> 22 <a id="svgTarget"><text>This is an SVG anchor element</text></a> 23 </svg> 24 </div> 25 26 <script> 27 test(function() { 28 assert_equals(getComputedStyle(subject).color, "rgb(0, 0, 0)", 29 "ancestor should be black"); 30 target.setAttribute("href", "/"); 31 assert_equals(getComputedStyle(subject).color, "rgb(0, 128, 0)", 32 "ancestor should be green since target is a link"); 33 target.removeAttribute("href"); 34 assert_equals(getComputedStyle(subject).color, "rgb(0, 0, 0)", 35 "ancestor should be black since target is no longer a link"); 36 }, ":any-link & :link pseudo-class invalidation with an HTML link"); 37 38 test(function() { 39 assert_equals(getComputedStyle(subject).color, "rgb(0, 0, 0)", 40 "ancestor should be black"); 41 svgTarget.setAttribute("href", "/") 42 assert_equals(getComputedStyle(subject).color, "rgb(0, 0, 255)", 43 "ancestor should be blue since target is a link"); 44 svgTarget.removeAttribute("href"); 45 assert_equals(getComputedStyle(subject).color, "rgb(0, 0, 0)", 46 "ancestor should be black since target is no longer a link"); 47 }, ":any-link & :link pseudo-class invalidation with an SVG link"); 48 </script>