setNamedItem
Summary
Adds an attribute to an element by using an attributes collection.
Method of dom/NamedNodeMapdom/NamedNodeMap
Syntax
var object = object.setNamedItem(/* see parameter list */);
Parameters
ppNode
- Data-type
- any
attribute
Return Value
Returns an object of type DOM NodeDOM Node
IHTMLDOMAttribute
attribute
attribute
Examples
The following example shows how to add an attribute to an element using the setNamedItem method.
<html>
<head>
<title>setNamedItem example</title>
<script>
function fnSetNamedItem(){
var nnm = myDIV.attributes;
var namedItem = document.createAttribute("title");
namedItem.value = "This is a ToolTip";
nnm.setNamedItem(namedItem);
}
</script>
</head>
<body onload="fnSetNamedItem();">
<div id="myDIV">This DIV now has a ToolTip.</div>
</body>
</html>
Notes
Remarks
An attribute that is set with this method does not have to apply to the element. If an attribute with the same name is already present, it is replaced by the new attribute. setNamedItem was introduced in Microsoft Internet Explorer 6.
Syntax
Standards information
Attributions
Mozilla Developer Network : [NamedNodeMap Article]
Microsoft Developer Network: [setNamedItem Method Article]