@todojs/

05.open-close

HTML, CSS, JS

No description

fork
loading
Files
  • index.html
index.html
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
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Open and Closed</title>
</head>
<body>
<div id="open"></div>
<div id="closed"></div>
<script>
  const divOpen            = document.querySelector ('#open');
  const shadowRootOpen     = divOpen.attachShadow ({mode : 'open'});
  shadowRootOpen.innerHTML = '<h1 part="h1">open</h1>';

  const divClosed            = document.querySelector ('#closed');
  const shadowRootClosed     = divClosed.attachShadow ({mode : 'closed'});
  shadowRootClosed.innerHTML = '<h1 part="h1">closed</h1>';

  if (divOpen.shadowRoot !== null) {
    divOpen.shadowRoot.querySelector ('h1').innerHTML = 'open means accesible';
  }
  if (divClosed.shadowRoot !== null) {
    divOpen.shadowRoot.querySelector ('h1').innerHTML = 'closed means unaccesible';
  }
</script>
</body>
</html>
result
console