Javascript Reference - HTML DOM Attribute Objects

In the HTML DOM (Document Object Model), everything is a node. The Attr object represents an HTML attribute.

An HTML attribute always belongs to an HTML element.

The NamedNodeMap object represents an unordered collection of an elements attribute nodes.

Nodes in a NamedNodeMap can be accessed by name or by index (number).

Browser Support

Attributes Yes Yes Yes Yes Yes

Properties and Methods

Property / Method Description
attr. Returns true if the attribute is of type Id, otherwise false Returns the name of an attribute
attr.value Sets or gets the value of the attribute
attr.specified Returns true if the attribute is specified, otherwise it returns false
nodemap.getNamedItem() Returns attribute node from a NamedNodeMap.
nodemap.item() Returns the node at a specified index in a NamedNodeMap
nodemap.length Returns the number of nodes in a NamedNodeMap
nodemap.removeNamedItem() Removes a specified attribute node
nodemap.() Sets the specified attribute node (by name)