This page shows you how to get a HTML/XML element's attribute's values. For example, values of {class, style, href, src, title, width, height, …}.
Use ‹node›.getAttribute(‹attribute name›) to get a element's attribute value. The ‹attribute name› should be a string. The ‹node› is a HTML element object.
If a attribute does not exist, it returns null or "".
For example, if you have a HTML tag like this:
<div id="id46570" class="xyz" style="color:red;font-size:larger" title="sample ele" width="300px" height="300px">sample element</div>
and you want to know its “title” attribue's value, do it like this:
var xx = document.getElementById("id46570"); var myTitle = xx.getAttribute("title"); alert("title is " + myTitle);
Test here: JavaScript test page: getAttribute.
As of , this works in all major browsers.
https://developer.mozilla.org/en/DOM/element.getAttribute