Adds an attribute to an element by using an attributes collection.
Method of dom/NamedNodeMapdom/NamedNodeMap
Syntaxvar object = object.setNamedItem();
Parameters ppNode
attribute
Return ValueReturns an object of type DOM NodeDOM Node
IHTMLDOMAttribute
attribute
attribute
ExamplesThe 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 AttributionsMozilla Developer Network : [NamedNodeMap Article]
Microsoft Developer Network: [setNamedItem Method Article]
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4