www.fgks.org   »   [go: up one dir, main page]

Click to Rate and Give Feedback
Methods
 setNamedItem Method
setNamedItem Method

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

Syntax

newretNode = attributes.setNamedItem(oNamedItem)

Parameters

oNamedItem Required. An attribute.

Return Value

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

Remarks

setNamedItem was introduced in Microsoft Internet Explorer 6.

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.

Example

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

<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 >
<DIV ID="myDIV">This DIV now has a ToolTip.</DIV>
</BODY>
</HTML>
This feature requires Microsoft® Internet Explorer 6 or later. Click the following icon to install the latest version. Then reload this page to view the sample.

Standards Information

This method is defined in World Wide Web Consortium (W3C) Document Object Model (DOM) Level 1 World Wide Web link.

Applies To

attributes
Tags What's this?: Add a tag
Community Content
 
Add Community Content
© 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker
DCSIMG