From http://www.w3schools.com (Copyright Refsnes Data)
Complete Element Object Reference
The setAttribute() method adds a new attribute.
If an attribute with that name already exists in the element, its value is changed to be that of the value parameter
| elementNode.setAttribute(name,value) |
| Parameter | Description |
|---|---|
| name | Required. Specifies the name of the attribute to set |
| value | Required. Specifies the value of the attribute to set |
The following code fragment loads "books.xml" into xmlDoc using loadXMLDoc() and adds an "edition" attribute to all <book> elements:
Example
Output:
Try it yourself » |
setAttribute() - Change an attribute's value
Complete Element Object Reference
From http://www.w3schools.com (Copyright Refsnes Data)