summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/LayoutTests/fast/selectors/shadow-host-div-with-text.html
blob: ced764eec9fc9c3cdade322039348535f1eb27d1 (plain)
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
<!DOCTYPE html>
<html>
<head>
  <style>
    body, #host {
      border: 0;
      margin: 0;
      padding: 0;
      font: 16px sans-serif;
    }
  </style>
</head>
<body>
  <template>
    <style>
      span::selection { background: rgba(255, 0, 0, 0.95); }
    </style>
    <span>
      Some hearts are diamonds some hearts are stones
    </span>
  </template>
  <div id=host></div>
  <script>
    var host = document.querySelector('#host');
    var template = document.querySelector('template');
    var root = host.createShadowRoot();
    root.appendChild(template.content);
    var span = root.querySelector('span');
    
    var selection = window.getSelection();
    var range = document.createRange();
    range.selectNodeContents(span);
    selection.addRange(range);
  </script>
</body>
</html>