Element.setAttributeNodeNS

  • Revision slug: DOM/element.setAttributeNodeNS
  • Revision title: element.setAttributeNodeNS
  • Revision id: 135358
  • Created:
  • Creator: Mgjbot
  • Is current revision? No
  • Comment robot Adding: [[ja:DOM:element.setAttributeNodeNS]] <<langbot>>

Revision Content

{{ DomRef() }}

Summary

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

Syntax

replacedAttr = element.setAttributeNodeNS(attributeNode) 
  • replacedAttr is the replaced attribute node, if any, returned by this function.
  • attributeNode is an Attr node.

Example

// <div id="one" special-align="utterleft">one</div> 
// <div id="two">two</div> 

var myns = "http://www.mozilla.org/ns/specialspace"; 
var d1 = document.getElementById("one"); 
var d2 = document.getElementById("two"); 
var a = d1.getAttributeNodeNS(myns, "special-align"); 
d2.setAttributeNodeNS(a); 

alert(d2.attributes[1].value) // returns: `utterleft'

Notes

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

{{ DOMAttributeMethods() }}

Specification

DOM Level 2 Core: setAttributeNodeNS


{{ languages( { "fr": "fr/DOM/element.setAttributeNodeNS", "ja": "ja/DOM/element.setAttributeNodeNS", "pl": "pl/DOM/element.setAttributeNodeNS" } ) }}

Revision Source

<p>
{{ DomRef() }}
</p>
<h3 name="Summary"> Summary </h3>
<p><code>setAttributeNodeNS</code> adds a new attribute node with the specified namespace and name.
</p>
<h3 name="Syntax"> Syntax </h3>
<pre class="eval"><i>replacedAttr</i> = element.setAttributeNodeNS(<i>attributeNode</i>) 
</pre>
<ul><li> <code>replacedAttr</code> is the replaced attribute node, if any, returned by this function.
</li><li> <code>attributeNode</code> is an <code>Attr</code> node.
</li></ul>
<h3 name="Example"> Example </h3>
<pre>// &lt;div id="one" special-align="utterleft"&gt;one&lt;/div&gt; 
// &lt;div id="two"&gt;two&lt;/div&gt; 

var myns = "http://www.mozilla.org/ns/specialspace"; 
var d1 = document.getElementById("one"); 
var d2 = document.getElementById("two"); 
var a = d1.getAttributeNodeNS(myns, "special-align"); 
d2.setAttributeNodeNS(a); 

alert(d2.attributes[1].value) // returns: `utterleft'
</pre>
<h3 name="Notes"> Notes </h3>
<p>If the specified attribute already exists on the element, then that attribute is replaced with the new one and the replaced one is returned.
</p><p>{{ DOMAttributeMethods() }}
</p>
<h3 name="Specification"> Specification </h3>
<p><a class="external" href="http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-ElSetAtNodeNS">DOM Level 2 Core: setAttributeNodeNS</a>
</p><p><br>
</p>
<div class="noinclude">
</div>
{{ languages( { "fr": "fr/DOM/element.setAttributeNodeNS", "ja": "ja/DOM/element.setAttributeNodeNS", "pl": "pl/DOM/element.setAttributeNodeNS" } ) }}
Revert to this revision