HTML DOM Attr Object
- Previous Page HTML Element
- Next Page HTML Event
Attr object
In HTML DOM,Attr objectrepresent HTML attributes.
HTML attributes always belong to HTML element.
NamedNodeMap
In HTML DOM,NamedNodeMap objectan unordered collection representing element attribute nodes.
In other words: NamedNodeMap is Attr object.
NamedNodeMap has a list that returns the number of nodes. length property.
Nodes can be accessed by name or index number. The index starts from 0.
Attribute properties
Attribute | description |
---|---|
isId | Deprecated. |
name | Returns the name of the attribute. |
value | Sets or returns the value of the attribute. |
specified | Returns true if the attribute is specified, otherwise returns false. |
NamedNodeMap properties and methods
method | description |
---|---|
getNamedItem() | Return the attribute node (by name) from the NamedNodeMap. |
item() | Return the attribute node (by index) from the NamedNodeMap. |
length | Return the number of attributes in the NamedNodeMap. |
removeNamedItem() | Remove attributes (nodes). |
setNamedItem() | Set attributes (nodes) by name. |
DOM 4 Warning!
In the W3C DOM Core, the Attr (attribute) object inherits all properties and methods from the Node object.
In DOM 4, the Attr object no longer inherits from the Node.
To ensure the safety of future code, you should avoid using the properties and methods of node objects on attribute objects:
Attribute / Method | Reasons to Avoid |
---|---|
attr.appendChild() | The attribute has no child nodes. |
attr.attributes | The attribute has no attributes. |
attr.baseURI | Use document.baseURI instead. |
attr.childNodes | The attribute has no child nodes. |
attr.cloneNode() | Use attr.value instead. |
attr.firstChild | The attribute has no child nodes. |
attr.hasAttributes() | The attribute has no attributes. |
attr.hasChildNodes | The attribute has no child nodes. |
attr.insertBefore() | The attribute has no child nodes. |
attr.isEqualNode() | It has no meaning. |
attr.isSameNode() | It has no meaning. |
attr.isSupported() | Always true. |
attr.lastChild | The attribute has no child nodes. |
attr.nextSibling | The attribute has no sibling nodes. |
attr.nodeName | Use attr.name instead. |
attr.nodeType | Always 2 (ATTRIBUTE_NODE). |
attr.nodeValue | Use attr.value instead. |
attr.normalize() | The attribute cannot be normalized. |
attr.ownerDocument | It is always your HTML document. |
attr.ownerElement | This is the HTML element you use to access the attribute. |
attr.parentNode | This is the HTML element you use to access the attribute. |
attr.previousSibling | The attribute has no sibling nodes. |
attr.removeChild | The attribute has no child nodes. |
attr.replaceChild | The attribute has no child nodes. |
attr.textContent | Use attr.value instead. |
- Previous Page HTML Element
- Next Page HTML Event