Attributes
HTML Attributes As Element Properties
HTMLElement and its subtypes define properties that correspond to the standard attributes of HTML elements. The HTMLElement objects that represent the elements of an HTML document define read/write properties that mirror the HTML attributes of the elements. HTMLElement defines properties for the universal HTTP attributes such as id, title lang, and dir, and event handler properties like onclick.
Geting and Setting Non-HTML Attributes
The Element type also defines getAttribute() and setAttribute() methods that you can use to query and set non- standard HTML attributes and to query and set attributes on the elements of an XML document:
Element also defines two related methods, hasAttribute() and removeAttribute(),
Dataset Attributes
HTML5 provides a solution. In an HTML5 document, any attribute whose name is lowercase and begins with the prefix “data-” is considered valid. HTML5 also defines a dataset property on Element objects. This property refers to an object, which has properties that correspond to the data- attributes with their prefix removed. Thus dataset.x would hold the value of the data-x attribute.
Attributes As Attr Nodes ?
There is one more way to work with the attributes of an Element. The Node type defines an attributes property. This property is null for any nodes that are not Element ob- jects. For Element objects, attributes is a read-only array-like object that represents all the attributes of the element.
document.body.attributes[0]
document.body.attributes.bgcolor
document.body.attributes["ONLOAD"]