HTML DOM PropertyObject
HTML DOM Nodes
In the HTML DOM (Document Object Model), everything isa node:
- The document is a document node
- All HTML elements are element nodes
- All HTML attributes are attribute nodes
- The text inserted into HTML elements is text nodes
- Comments are comment nodes
Attr Object
In the HTML DOM,the Attr objectrepresents an HTML attribute.
HTML attributes always belong to HTML elements.
NamedNodeMap Object
In the HTML DOM, theNamedNodeMap objectrepresents an unordered list of nodes.
We can access the nodes in a NamedNodeMap by node name.
Browser Support
![]()
![]()
![]()
![]()
![]()
All major browsers support the Attr object and the NamedNodeMap object.
| Property / Method | Description |
|---|---|
| attr.isId | The isId property returns true if the attribute is of ID type, otherwise it 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() | Deletes 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 a node object.
In DOM 4, the Attr (attribute) object no longer inherits from the node object.
For the sake of long-term code quality, you should avoid using node object properties and methods on attribute objects:
| Property / Method | Reason to avoid |
|---|---|
| attr.appendChild() | Attribute has no child nodes |
| attr.attributes | Attribute has no attributes |
| attr.baseURI | Use document.baseURI instead |
| attr.childNodes | Attribute has no child nodes |
| attr.cloneNode() | Use attr.value instead |
| attr.firstChild | Attribute has no child nodes |
| attr.hasAttributes() | Attribute has no attributes |
| attr.hasChildNodes | Attribute has no child nodes |
| attr.insertBefore() | Attribute has no child nodes |
| attr.isEqualNode() | No meaning |
| attr.isSameNode() | No meaning |
| attr.isSupported() | Usually true |
| attr.lastChild | Attribute has no child nodes |
| attr.nextSibling | Attribute has no sibling nodes |
| attr.nodeName | Useattr.name instead |
| attr.nodeType | Usually 2 (ATTRIBUTE-NODE) |
| attr.nodeValue | Useattr.value instead |
| attr.normalize() | Attribute has no specification |
| 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 | Attribute has no sibling nodes |
| attr.removeChild | Attribute has no child nodes |
| attr.replaceChild | Attribute has no child nodes |
| attr.textContent | Useattr.value instead |