Element.setAttributeNS( ): create or change an attribute with a namespace — DOM Level 2 Core:


void setAttributeNS(StringnamespaceURI,
                    String qualifiedName,
                    String value)
    throws DOMException;



The URI that uniquely identifies the namespace of the attribute to be set or created, or null for no namespace.


The name of the attribute, specified as an optional namespace prefix and colon followed by the local name within the namespace.


The new value of the attribute.


This method may throw a DOMException with the following code values:


The qualifiedName argument contains a character that is not allowed in HTML or XML attribute names.


qualifiedName is malformed, or there is a mismatch between the namespace prefix of qualifiedName and the namespaceURI argument.


This element is read-only and does not allow modifications to its attributes.


The DOM implementation does not support XML documents.


This method is like setAttribute( ), except that the attribute to be created or set is specified by a namespace URI and a qualified name that consists of a namespace prefix, a colon, and a local name within the namespace.

This method is useful only with XML documents that use namespaces. It may be unimplemented (i.e., throw a NOT_SUPPORTED_ERR) on browsers that do not support XML documents.

See Also

Element.setAttribute( ), Element.setAttributeNode( )

Get JavaScript: The Definitive Guide, 5th Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.