The attr type represents the attribute elements of HTML. This type is implemented in all browsers. It inherits all properties and methods of the node object.

Note: From the DOM 4 it is no longer inherited from Node, hence Node methods and properties like insertBefore(), appendChild(), hasChildNodes() …etc should be refrained from using. 

The characteristics of attr type are:

  • nodeType : 2
  • nodeName : attribute name
  • nodeValue : attribute value
  • parentNode : null
  • childNode : none in HTML

The attr type properties

  • – This property is attribute’s name or nodeName.
  • attr.value – This property is value of attribute or nodeValue.
  • attr.specified – It is boolean which is set to true if attribute is created, irrespective of it is attached to element or not.
  • attr.isId – It is boolean which returns true if attribute is of type ID, else return false. This is DOM level 3 implementation and is not functional in any browsers yet.

An attribute is created using document.createAttribute(“attr”) and passing the name of the attribute.

The attr type methods

Read more about attribute type methods at this link!

Example how to properly implement and manipulate HTML attributes with DOM methods


›› go to examples ››