files/en-us/web/api/document/createattributens/index.md
{{ ApiRef("DOM") }}
The Document.createAttributeNS() method creates a new attribute node
with the specified namespace URI and qualified name, and returns it.
The object created is a node implementing the
{{domxref("Attr")}} interface. The DOM does not enforce what sort of attributes can be
added to a particular element in this manner.
createAttributeNS(namespaceURI, qualifiedName)
namespaceURI
qualifiedName
qualifiedName.The new {{domxref("Attr")}} node.
NamespaceError {{domxref("DOMException")}}
namespaceURI value is not a valid namespace URI.InvalidCharacterError {{domxref("DOMException")}}
qualifiedName value is not a valid XML name; for example, it starts with a number, hyphen, or period, or contains characters other than alphanumeric characters, underscores, hyphens, or periods.const node = document.getElementById("svg");
const a = document.createAttributeNS("http://www.w3.org/2000/svg", "viewBox");
a.value = "0 0 100 100";
node.setAttributeNode(a);
console.log(node.getAttribute("viewBox")); // "0 0 100 100"
{{Specifications}}
{{Compat}}