HTML DOM setNamedItem () method
Examples
Set H1 class attribute:
var btn=document.getElementsByTagName("h1")[0];
var typ=document.createAttribute("class");
typ.nodeValue="democlass";
btn.attributes.setNamedItem(typ);
var typ=document.createAttribute("class");
typ.nodeValue="democlass";
btn.attributes.setNamedItem(typ);
Setting properties ago:
Hello world
Setting property:
Hello world
try it"
Definition and Usage
setNamedItem () method is used to add a specified node.
If the node already exists, it is replaced, and returns the value of the replacement node, otherwise it will return null.
Browser Support
All major browsers support setNamedItem () method
grammar
namednodemap.setNamedItem( node )
parameter
参数 | 类型 | 描述 |
---|---|---|
node | 节点对象 | 必须。在节点列表中你想替换的节点。 |
return value
类型 | 描述 |
---|---|
节点对象 | 返回替换的节点,如果没有替换则返回 null |
technical details
DOM version | Core Level 1 |
---|