go
Expand Minimize
This topic has not yet been rated - Rate this topic

setNamedItem method

Adds an attribute to an element by using an attributes collection.

Document Object Model (DOM) Level 3 Core Specification, Section 1.4

Syntax

var retval = attributes.setNamedItem(ppNode);

Parameters

ppNode [in]

Type: IHTMLDOMAttribute

An attribute object.

Return value

Type: IHTMLDOMAttribute

Returns the previously existing attribute if it has the same name as the new attribute, otherwise null.

Standards information

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.

Examples

The following example shows how to add an attribute to an element using the setNamedItem method.

Code example: http://samples.msdn.microsoft.com/workshop/samples/author/dhtml/refs/setNamedItemEx1.htm


<HTML>
<HEAD>
<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>


See also

attributes
Reference
getNamedItem
removeNamedItem

 

 

Send comments about this topic to Microsoft

Build date: 11/27/2012

Did you find this helpful?
(1500 characters remaining)

Community Additions

ADD
© 2013 Microsoft. All rights reserved.