This page shows you how to set a HTML/XML element's attribute, such as the values of {class, href, src, title, width, height, …}.
Use .setAttribute(‹attribute name›, ‹value›) to set a element's attribute. The ‹attribute name› should be a string. ‹value› should be a string.
If a attribute does not exist, it will be created.
HTML code:
<div id="id95680" class="xyz" title="important">important</div>
JavaScript code:
document.getElementById("id95680").setAttribute("title", "NO");
Test here: JavaScript test page: setAttribute.
As of , this works in all major browsers.
https://developer.mozilla.org/en/DOM/element.setAttribute