Node-mutation-adoptNode.html (1372B)
1 <!DOCTYPE html> 2 <meta charset=utf-8> 3 <title>Node-manipulation-adopted</title> 4 <link rel=help href="https://dom.spec.whatwg.org/#dom-domimplementation-createhtmldocument"> 5 <link rel=help href="https://dom.spec.whatwg.org/#mutation-algorithms"> 6 <script src="/resources/testharness.js"></script> 7 <script src="/resources/testharnessreport.js"></script> 8 <div id="log"></div> 9 <script> 10 "use strict"; 11 12 test(() => { 13 const old = document.implementation.createHTMLDocument(""); 14 const div = old.createElement("div"); 15 div.appendChild(old.createTextNode("text")); 16 assert_equals(div.ownerDocument, old); 17 assert_equals(div.firstChild.ownerDocument, old); 18 document.body.appendChild(div); 19 assert_equals(div.ownerDocument, document); 20 assert_equals(div.firstChild.ownerDocument, document); 21 }, "simple append of foreign div with text"); 22 23 test(function() { 24 var div = document.createElement("div"); 25 div.id = "foobar"; 26 27 assert_equals(div.ownerDocument, document); 28 assert_equals(div.attributes[0].ownerDocument, document); 29 30 var other_doc = document.implementation.createHTMLDocument(); 31 other_doc.body.appendChild(div); 32 33 assert_equals(div.ownerDocument, other_doc); 34 assert_equals(div.attributes[0].ownerDocument, other_doc); 35 }, "Adopting an element into a different document update's the element's owner doc as well as the owner docs of it's attributes") 36 37 </script>