ZVON > References > DOM2 Reference

setAttributeNS (method )

Owning interface and usage:  
Element.setAttributeNS(namespaceURI, qualifiedName, value)

Member of these other interfaces:  
none

Description:  
Adds a new attribute.

Parameters:  
DOMString namespaceURI  -  The namespace URI of the attribute to create or alter.
DOMString qualifiedName  -  The qualified name of the attribute to create or alter.
DOMString value  -  Value to set in string form.

Returns:  
nothing

Exceptions:  
DOMException INVALID_CHARACTER_ERR
Raised if the specified qualified name contains an invalid character.
DOMException NO_MODIFICATION_ALLOWED_ERR
Raised if this node is readonly.
DOMException NAMESPACE_ERR
Raised if the qualifiedName is malformed, if the qualifiedName has a prefix and the namespaceURI is null, if the qualifiedName has a prefix that is "xml" and the namespaceURI is different from "http://www.w3.org/XML/1998/namespace", or if the qualifiedName is "xmlns" and the namespaceURI is different from "http://www.w3.org/2000/xmlns/".

Note:  
If an attribute with the same local name and namespace URI is already present on the element, its prefix is changed to be the prefix part of the qualifiedName, and its value is changed to be the value parameter. This value is a simple string; it is not parsed as it is being set. So any markup (such as syntax to be recognized as an entity reference) is treated as literal text, and needs to be appropriately escaped by the implementation when it is written out. In order to assign an attribute value that contains entity references, the user must create an Attr node plus any Text and EntityReference nodes, build the appropriate subtree, and use setAttributeNodeNS or setAttributeNode to assign it as the value of an attribute.


Example:
Text in the first DIV.
x a b x
Text in the last DIV.
Source:
   <div id="doc" xmlns:svg="http://www.w3.org/2000/svg">
     <div>
       Text in the first DIV.
     </div>
     <svg:svg id="logo" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="60">
       <svg:g style="fill:#3399cc; font-size:36pt; font-family:'dialog'; font-weight: bold">
         <svg:a xlink:type="simple" xlink:href="http://www.zvon.org">
           <svg:text x="50%" y="65%" text-anchor="middle">ZVON.org</svg:text>
         </svg:a>
       </svg:g>
     </svg:svg>
     <apply xmlns="http://www.w3.org/1998/Math/MathML">
   <int/> 
   <bvar> 
     <ci> x </ci> 
   </bvar> 
   <interval> 
     <ci> a </ci> 
     <ci> b </ci> 
   </interval> 
   <apply>
     <cos/> 
     <ci> x </ci> 
   </apply> 
     </apply> 
     <div>
       Text in the last DIV.
     </div>
   </div>
     
JavaScript:
  var elem = document.getElementById('doc');
  elem.setAttributeNS('http://zvon.org/namespaces/test', 'attr', 'temporary');
  var output = elem.getAttributeNS('http://zvon.org/namespaces/test', 'attr');
Output:
desired your browser
temporary