TOC PREV NEXT INDEX

domref



setAttributeNodeNS


setAttributeNodeNS adds a new attribute node with the specified namespace and name.

Syntax

replaced_attr =
  element.setAttributeNodeNS(namespace, attribute)
 

Parameters

namespace is the namespace of the attribute as a string.

attribute is a node of type Attribute.

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

Example

// <div id="one" special-align="utterleft">one</div>
 
// <div id="two">two</div>
 
myns = "http://www.mozilla.org/ns/specialspace";
 

 
d1 = document.getElementById("one");
 
d2 = document.getElementById("two");
 
a = d1.getAttributeNodeNS(
  myns,
  "special-align");
 
d2.setAttributeNodeNS(
 
  myns,
 
  a);
 
alert(d2.attributes[1].value)
 
// returns: `utterleft'
 

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. The corresponding getter method for namespaced attribute nodes is getAttributeNodeNS.

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

Specification

setAttributeNodeNS
 


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