diff --git a/lib/morph.js b/lib/morph.js index ccc20cf..f32eb48 100644 --- a/lib/morph.js +++ b/lib/morph.js @@ -47,9 +47,16 @@ function copyAttrs (newNode, oldNode) { attrNamespaceURI = attr.namespaceURI attrValue = attr.value if (attrNamespaceURI) { - attrName = attr.localName || attrName - fromValue = oldNode.getAttributeNS(attrNamespaceURI, attrName) + var attrLocalName = attr.localName + + // Important: getAttributeNS expects the localName of a namespaced attribute + // ref: https://dom.spec.whatwg.org/#dom-element-getattributens + // ref: https://www.w3.org/TR/DOM-Level-2-Core/glossary.html#dt-localname + fromValue = oldNode.getAttributeNS(attrNamespaceURI, attrLocalName || attrName) if (fromValue !== attrValue) { + // but setAttributeNS requires the fully qualified name + // ref: https://dom.spec.whatwg.org/#dom-element-setattributens + // ref: https://www.w3.org/TR/DOM-Level-2-Core/glossary.html#dt-qualifiedname oldNode.setAttributeNS(attrNamespaceURI, attrName, attrValue) } } else {