HTML DOM setAttributeNode () method
Examples
var atr=document.createAttribute("class");
atr.nodeValue="democlass";
document.getElementsByTagName("H1")[0].setAttributeNode(atr);
atr.nodeValue="democlass";
document.getElementsByTagName("H1")[0].setAttributeNode(atr);
Setting the attribute node:
Hello World
After setting attribute node:
Hello World
try it"
Definition and Usage
setAttributeNode () method is used to add a new attribute node.
If the attribute specifies the name of the element already exists, then the property will be a new property instead. If the new attribute replaces an existing attribute, the replaced property is returned, otherwise returns NULL.
Browser Support
All major browsers support setAttributeNode () method
grammar
element .setAttributeNode( attributenode )
parameter
参数 | 类型 | 描述 |
---|---|---|
attributenode | Attr 对象 | 必须。你要添加的属性节点。 |
return value
类型 | 描述 |
---|---|
Attr 对象 | 替换的属性节点, 如果没有则返回 null |
technical details
DOM version | Core Level 1 Element Object |
---|