HTML DOM setAttributeNode()Method
Example
var atr=document.createAttribute("class");
atr.nodeValue="democlass";
document.getElementsByTagName("H1")[0].setAttributeNode(atr);
atr.nodeValue="democlass";
document.getElementsByTagName("H1")[0].setAttributeNode(atr);
Before setting the attribute node:
Hello World
After setting the attribute node:
Hello World
Try it yourself »
Definition and Usage
The setAttributeNode() method is used to add a new attribute node.
If an attribute with the specified name already exists in the element, it will be replaced by the new attribute. If the new attribute replaces an existing attribute, the replaced attribute is returned; otherwise, NULL is returned.
Browser Support
![]()
![]()
![]()
![]()
![]()
All major browsers support the setAttributeNode() method
Syntax
element.setAttributeNode(attributenode)
Parameter
| Parameter | Type | Description |
|---|---|---|
| attributenode | Attr object | Required. The attribute node you want to add. |
Return Value
| Type | Description |
|---|---|
| Attr object | The replaced attribute node, or NULL if there is nonenull |
Technical Details
| DOM Version | Core Level 1 Element Object |
|---|
Other Extensions
Element Object