Sets the value of an attribute on the specified element. If the attribute already exists, the value is updated; otherwise a new attribute is added with the specified name and value. Show To get the current value of an attribute, use
A string specifying the name of the attribute whose value is to be set. The attribute name is automatically converted to all lower-case when value A string containing the value to assign to the attribute. Any non-string value specified is converted automatically into a string. Boolean attributes are considered to be 1) or the attribute's name, with no leading or trailing whitespace. See the below for a practical demonstration.Since the specified 3 doesn't necessarily do what you expect. Instead of removing the attribute or setting its value to be 3, it instead sets the attribute's value to the string 5. If you wish to remove an attribute, call removeAttribute() .None ( 7). 8 9The specified attribute In the following example, 2.
This demonstrates two things:
DOM methods dealing with element's attributes: Not namespace-aware, most commonly used methodsNamespace-aware variants (DOM Level 2)DOM Level 1 methods for dealing with 2 nodes directly (seldom used)DOM Level 2 namespace-aware methods for dealing with 2 nodes directly (seldom used) 4 (DOM 1) 5 6 7 8 (DOM 1) 9getAttribute() 0getAttribute() 1getAttribute() 2 (DOM 2)getAttribute() 3--getAttribute() 4 (DOM 1)getAttribute() 5getAttribute() 6-BCD tables only load in the browserwith JavaScript enabled. Enable JavaScript to view data. Using |