Javascript - DOM - getAttribute
javascript-dom-a-list-of-dom-methods
How can we use getAttribute?
attributeValue = element.getAttribute(attributeName)
Given the attribute's name, getAttribute should return the value of that attribute. However, in some case, we may need to use .value:
var attribute = element.getAttribute(attributeName);
var attributeValue = attribute.value;
In some version of IE, getAttribute may return null even when the attribute exists. To get the attribute value, we may need to use the .attributes collection:
var attribute = element.attributes[attributeName];
var attributeValue = attribute.value;
page revision: 1, last edited: 03 Oct 2015 02:10