Source code
Revision control
Copy as Markdown
Other Tools
Test Info:
- This WPT test may be referenced by the following Test IDs:
- /dom/nodes/attributes-namednodemap-cross-document.window.html - WPT Dashboard Interop Dashboard
"use strict";
test(() => {
const element = document.createElement("div");
element.setAttribute("x", "first");
const attribute = element.attributes[0];
assert_equals(attribute.ownerDocument, document);
const otherDocument = new Document();
const otherElement = otherDocument.createElement("other");
assert_throws_dom("InUseAttributeError", () => otherElement.attributes.setNamedItem(attribute));
element.removeAttribute("x");
otherElement.attributes.setNamedItem(attribute);
assert_equals(attribute.ownerDocument, otherDocument);
}, "Moving an attribute between documents");
test(() => {
const element = document.createElement("div");
element.setAttribute("x", "first");
const attribute = element.attributes[0];
element.removeAttribute("x");
const otherDocument = new Document();
const otherElement = otherDocument.createElement("other");
otherElement.setAttribute("x", "second");
otherElement.attributes.setNamedItem(attribute);
assert_equals(attribute.ownerDocument, otherDocument);
assert_equals(otherElement.getAttribute("x"), "first");
}, "Replacing an attribute across documents");