Name
Element.setAttributeNode( ): add a new Attr node to an Element — DOM Level 1 Core:
Synopsis
Attr setAttributeNode(AttrnewAttr)
throws DOMException;Arguments
-
newAttr The Attr node that represents the attribute to be added or whose value is to be modified.
Returns
The Attr node that was replaced by
newAttr, or null if no attribute was
replaced.
Throws
This method may throw a DOMException with a code of the following values:
-
INUSE_ATTRIBUTE_ERR newAttris already a member of the attribute set of some other Element node.-
NO_MODIFICATION_ALLOWED_ERR The Element node is read-only and does not allow modifications to its attributes.
-
WRONG_DOCUMENT_ERR newAttrhas a differentownerDocumentproperty than the Element on which it is being set.
Description
This method adds a new Attr node to the set of attributes of
an Element node. If an attribute with the same name already exists
for the Element, newAttr replaces that
attribute, and the replaced Attr node is returned. If no such
attribute already exists, this method defines a new attribute for
the Element.
It is usually easier to use setAttribute( ) instead of setAttributeNode( ).
See Also
Attr, Document.createAttribute( ), Element.setAttribute( )
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access