Source Code:
(back to article)
Submit
Result:
Report an issue
<div id="interactive-host"></div> <script> const interactiveHost = document.getElementById('interactive-host'); const shadowRoot = interactiveHost.attachShadow({ mode: 'open' }); shadowRoot.innerHTML = ` <button id="shadow-btn">Click me</button> `; const shadowButton = shadowRoot.getElementById('shadow-btn'); shadowButton.addEventListener('click', () => { alert('Button inside Shadow DOM clicked!'); }); </script>