Element.hasAttributeNS

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

Revision Content

{{template.DomRef()}}

Summary

hasAttributeNS returns a boolean value indicating whether the current element has the specified attribute.

Syntax

result = element.hasAttributeNS(namespace, localName) 
  • result is the boolean value true or false.
  • namespace is a string specifying the namespace of the attribute.
  • localName is the name of the attribute.

Example

// check that the attribute exists 
// before you set a value 
var d = document.getElementById("div1"); 
if (d.hasAttributeNS( 
        "http://www.mozilla.org/ns/specialspace/", 
        "special-align")) {
   d.setAttribute("align", "center");
}

Notes

{{template.DOMAttributeMethods()}}

Specification

DOM Level 2 Core: hasAttributeNS

{{ wiki.languages( { "fr": "fr/DOM/element.hasAttributeNS", "pl": "pl/DOM/element.hasAttributeNS" } ) }}

Revision Source

<p>
{{template.DomRef()}}
</p>
<h3 name="Summary"> Summary </h3>
<p><code>hasAttributeNS</code> returns a boolean value indicating whether the current element has the specified attribute.
</p>
<h3 name="Syntax">Syntax </h3>
<pre class="eval"><i>result</i> = <i>element</i>.hasAttributeNS(<i>namespace</i>, <i>localName</i>) 
</pre>
<ul><li> <code>result</code> is the boolean value <code>true</code> or <code>false</code>.  
</li><li> <code>namespace</code> is a string specifying the namespace of the attribute.
</li><li> <code>localName</code> is the name of the attribute.
</li></ul>
<h3 name="Example"> Example </h3>
<pre>// check that the attribute exists 
// before you set a value 
var d = document.getElementById("div1"); 
if (d.hasAttributeNS( 
        "http://www.mozilla.org/ns/specialspace/", 
        "special-align")) {
   d.setAttribute("align", "center");
}
</pre>
<h3 name="Notes"> Notes </h3>
<p>{{template.DOMAttributeMethods()}}
</p>
<h3 name="Specification"> Specification </h3>
<p><a class="external" href="http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-ElHasAttrNS">DOM Level 2 Core: hasAttributeNS</a>
</p>
<div class="noinclude">
</div>
{{ wiki.languages( { "fr": "fr/DOM/element.hasAttributeNS", "pl": "pl/DOM/element.hasAttributeNS" } ) }}
Revert to this revision