TOC PREV NEXT INDEX

domref



setAttributeNode


setAttributeNode adds a new attribute node to the current element.

Syntax

replaced_attr = element.setAttributeNode(attribute)
 

Parameters

attribute is a node of type Attribute

replaced_attr is the replaced attribute node, if any, returned by this function

Example

// <div id="one" align="left">one</div>
 
// <div id="two">two</div>
 
d1 = document.getElementById("one");
 
d2 = document.getElementById("two");
 
a = d1.getAttributeNode("align");
 
d2.setAttributeNode(a);
 
alert(d2.attributes[1].value)
 
// returns: `left'
 

Notes

If the attribute named already exists on the element, then that attribute is replaced with the new one and the replaced one is returned.

Note that this function does not the set the value of the new attribute, only creates it on the element. Use setAttribute to set or change the value on an existing node.

Specification

setAttributeNode
 


Netscape Communications
http://developer.netscape.com
TOC PREV NEXT INDEX