-
Notifications
You must be signed in to change notification settings - Fork 0
/
text-content.html
46 lines (41 loc) · 1.13 KB
/
text-content.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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<!DOCTYPE html>
<html>
<head>
<title>Custom Elements: textContent</title>
<meta name="author" title="Eugene Kashida" href="mailto:[email protected]">
</head>
<body>
<script>
class MyParent extends HTMLElement {
constructor() {
super();
this._shadowRoot = this.attachShadow({ mode: 'open' });
}
connectedCallback() {
this._shadowRoot.innerHTML = `
<my-child>
<p>foo</p>
</my-child>
`;
}
}
class MyChild extends HTMLElement {
constructor() {
super();
this._shadowRoot = this.attachShadow({ mode: 'open' });
}
connectedCallback() {
this._shadowRoot.innerHTML = `
<div><slot>default content</slot></div>
`;
}
}
customElements.define('my-parent', MyParent);
customElements.define('my-child', MyChild);
var myParent = document.createElement('my-parent');
document.body.appendChild(myParent);
var myChild = myParent.shadowRoot.querySelector('my-child');
console.log('text content of element in shadow does not have access to light:', myChild.shadowRoot.querySelector('div').textContent);
</script>
</body>
</html>