Set a H1's class attribute:
Before setting the attribute:
After setting the attribute:
The setNamedItem() method adds the specified node to the NamedNodeMap.
If the node already exists, it will be replaced, and the replaced node will be the return value, otherwise the return value will be null.
Tip: Instead of working with attribute nodes, you could use the element.setAttribute() method to add an attribute with a value to an element.
Method | |||||
---|---|---|---|---|---|
setNamedItem() | Yes | Yes | Yes | Yes | Yes |
Parameter | Type | Description |
---|---|---|
node | Node object | Required. The node you want to add/replace in the NamedNodeMap collection |
Return Value: | A Node object, representing the replaced node (if any), otherwise null |
---|---|
DOM Version | Core Level 1 |