2019-12-03 04:33:44 +03:00
|
|
|
<script>
|
|
|
|
window.addEventListener('DOMContentLoaded', () => {
|
|
|
|
const outer = document.createElement('section');
|
|
|
|
document.body.appendChild(outer);
|
|
|
|
|
|
|
|
const root1 = document.createElement('div');
|
2020-05-07 23:36:54 +03:00
|
|
|
root1.setAttribute('id', 'root1');
|
2019-12-03 04:33:44 +03:00
|
|
|
outer.appendChild(root1);
|
|
|
|
const shadowRoot1 = root1.attachShadow({mode: 'open'});
|
|
|
|
const span1 = document.createElement('span');
|
2020-04-04 06:47:08 +03:00
|
|
|
span1.setAttribute('data-testid', 'foo');
|
2019-12-03 04:33:44 +03:00
|
|
|
span1.textContent = 'Hello from root1';
|
|
|
|
shadowRoot1.appendChild(span1);
|
|
|
|
|
|
|
|
const root2 = document.createElement('div');
|
|
|
|
shadowRoot1.appendChild(root2);
|
|
|
|
const shadowRoot2 = root2.attachShadow({mode: 'open'});
|
|
|
|
const span2 = document.createElement('span');
|
2020-04-04 06:47:08 +03:00
|
|
|
span2.setAttribute('data-testid', 'foo');
|
|
|
|
span2.setAttribute('id', 'target');
|
2019-12-03 04:33:44 +03:00
|
|
|
span2.textContent = 'Hello from root2';
|
|
|
|
shadowRoot2.appendChild(span2);
|
|
|
|
|
|
|
|
const root3 = document.createElement('div');
|
|
|
|
shadowRoot1.appendChild(root3);
|
|
|
|
const shadowRoot3 = root3.attachShadow({mode: 'open'});
|
|
|
|
const span3 = document.createElement('span');
|
2020-04-04 06:47:08 +03:00
|
|
|
span3.setAttribute('data-testid', 'foo');
|
2019-12-03 04:33:44 +03:00
|
|
|
span3.textContent = 'Hello from root3';
|
|
|
|
shadowRoot3.appendChild(span3);
|
2020-04-13 23:04:27 +03:00
|
|
|
const span4 = document.createElement('span');
|
|
|
|
span4.textContent = 'Hello from root3 #2';
|
|
|
|
span4.setAttribute('attr', 'value space');
|
|
|
|
shadowRoot3.appendChild(span4);
|
2019-12-03 04:33:44 +03:00
|
|
|
});
|
|
|
|
</script>
|