Easy Tutorial
❮ Prop Button Value Prop Img Vspace ❯

HTML DOM Attribute Object


HTML DOM Nodes

In the HTML DOM (Document Object Model), everything is a node:


Attr Object

In the HTML DOM, the Attr object represents an HTML attribute.

HTML attributes always belong to an HTML element.


NamedNodeMap Object

In the HTML DOM, the NamedNodeMap object represents an unordered list of nodes.

We can access the nodes in a NamedNodeMap by their node names.


Browser Support

All major browsers support the Attr object and the NamedNodeMap object.


Property / Method Description
attr.isId Returns true if the attribute is of type ID, otherwise returns false.
attr.name Returns the attribute name
attr.value Sets or returns the attribute value
attr.specified Returns true if the attribute is specified, otherwise returns false
nodemap.getNamedItem() Returns the specified attribute node from the node list.
nodemap.item() Returns the node at the specified index in the node list.
nodemap.length Returns the number of nodes in the node list.
nodemap.removeNamedItem() Removes the specified attribute node
nodemap.setNamedItem() Sets the specified attribute node (by name)

DOM 4 Warning !!!

In the W3C DOM Core, the Attr (attribute) object inherits all properties and methods of the Node object.

In DOM 4, the Attr (attribute) object no longer inherits from the Node object.

Considering long-term code quality, you should avoid using Node object properties and methods in attribute objects:

Property / Method Reason to Avoid
attr.appendChild() Attributes do not have child nodes
attr.attributes Attributes do not have attributes
attr.baseURI Use document.baseURI instead
attr.childNodes Attributes do not have child nodes
attr.cloneNode() Use attr.value instead
attr.firstChild Attributes do not have child nodes
attr.hasAttributes() Attributes do not have attributes
attr.hasChildNodes Attributes do not have child nodes
attr.insertBefore() Attributes do not have child nodes
attr.isEqualNode() Not meaningful
attr.isSameNode() Not meaningful
attr.isSupported() Usually true
attr.lastChild Attributes do not have child nodes
attr.nextSibling Attributes do not have sibling nodes
attr.nodeName Use attr.name instead
attr.nodeType Usually 2 (ATTRIBUTE-NODE)
attr.nodeValue Use attr.value instead
attr.normalize() Attributes do not have normalization
attr.ownerDocument Usually your HTML document
attr.ownerElement The HTML element you used to access the attribute
attr.parentNode The HTML element you used to access the attribute
attr.previousSibling Attributes do not have sibling nodes
attr.removeChild Attributes do not have child nodes
attr.replaceChild Attributes do not have child nodes
attr.textContent Use attr.value instead
❮ Prop Button Value Prop Img Vspace ❯