25.106. Element.setAttribute( ): create or change an attribute of an elementDOM Level 1 Core:25.106.1. Synopsisvoid setAttribute(String name, String value) throws DOMException; 25.106.1.1. Arguments
25.106.1.2. ThrowsThis method may throw a DOMException with the following code values:
25.106.2. DescriptionThis method sets the specified attribute to the specified value. If no attribute by that name already exists, a new one is created. Note that HTMLElement objects of an HTML document define JavaScript properties that correspond to all standard HTML attributes. Thus, you need to use this method only if you want to set a nonstandard attribute. 25.106.3. Example// Set the TARGET attribute of all links in a document var links = document.body.getElementsByTagName("a"); for(var i = 0; i < links.length; i++) { links[i].setAttribute("target", "newwindow"); // Or more easily: links[i].target = "newwindow" } 25.106.4. See AlsoElement.getAttribute( ), Element.removeAttribute( ), Element.setAttributeNode( ) |