getElementById-dynamic-001.html (973B)
1 <!doctype html> 2 <title>Shadow DOM: ShadowRoot.getElementById in shadow trees keeps working after host is removed from tree</title> 3 <link rel="help" href="https://dom.spec.whatwg.org/#dom-nonelementparentnode-getelementbyid"> 4 <link rel="help" href="https://bugzil.la/1475203"> 5 <link rel="author" name="Emilio Cobos Álvarez" href="emilio@crisal.io"> 6 <script src="/resources/testharness.js"></script> 7 <script src="/resources/testharnessreport.js"></script> 8 <div id="host"></div> 9 <script> 10 test(function() { 11 let host = document.getElementById("host"); 12 host.attachShadow({ mode: "open" }).innerHTML = `<div id="test-id"></div>`; 13 14 let element = host.shadowRoot.getElementById("test-id"); 15 assert_true(!!element); 16 17 host.remove(); 18 assert_equals(host.shadowRoot.getElementById("test-id"), element); 19 20 element.remove(); 21 assert_equals(host.shadowRoot.getElementById("test-id"), null); 22 }, "ShadowRoot.getElementById keeps working after host has been removed"); 23 </script>