Source code
Revision control
Copy as Markdown
Other Tools
Test Info:
- This WPT test may be referenced by the following Test IDs:
            
- /css/css-highlight-api/highlight-text-dynamic.html - WPT Dashboard Interop Dashboard
 
 
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Highlights Paint after dynamic creation.</title>
    <link rel="mismatch" href="highlight-text-dynamic-notref.html">
    <meta name="assert" content="Highlight should paint after being created after first paint.">
    <style>
        ::highlight(example-highlight) {
            background-color: yellow;
            color:green;
        }
    </style>
</head>
<body>
    <span id="text1">One two three</span>
    <script>
        function setHighlight(timestamp) {
            let textElement = document.getElementById('text1');
            let highlight1 = new Highlight(new StaticRange({startContainer: textElement.childNodes[0], startOffset: 1, endContainer: textElement.childNodes[0], endOffset: 2}));
            CSS.highlights.set("example-highlight", highlight1);
        }
        document.body.offsetLeft;
        window.requestAnimationFrame(setHighlight);
    </script>
</body>
</html>