attribute of element js code example
Example 1: get element attribute javascript
var x = document.getElementsByTagName("H1")[0].getAttribute("class");
Example 2: attribute in javascript
elem.hasAttribute(name) //checks for existence.
elem.getAttribute(name) //gets the value.
elem.setAttribute(name, value) //sets the value.
elem.removeAttribute(name) //removes the attribute.
elem.attributes //collection of all attributes.