--- title: element.hasAttributeNS slug: Web/API/Element/hasAttributeNS tags: - DOM - Gecko - 翻訳中 translation_of: Web/API/Element/hasAttributeNS --- <p>{{ ApiRef() }}</p> <h3 id=".E6.A6.82.E8.A6.81" name=".E6.A6.82.E8.A6.81">概要</h3> <p><code>hasAttributeNS</code> は現在の要素が指定した属性を所有するか否かを示す boolean 値を返します。</p> <h3 id=".E6.A7.8B.E6.96.87" name=".E6.A7.8B.E6.96.87">構文</h3> <pre class="eval"><em>result</em> =<em>element</em>.hasAttributeNS(<em>namespace</em>,<em>localName</em>) </pre> <ul> <li><code>result</code> は <code>true</code> もしくは <code>false</code> の boolean 値です。</li> <li><code>namespace</code> は属性の名前空間を特定する文字列です。</li> <li><code>localName</code> は属性の名前です。</li> </ul> <h3 id=".E4.BE.8B" name=".E4.BE.8B">例</h3> <pre>// 値をセットする前に属性が存在しているか検証します。 var d = document.getElementById("div1"); if (d.hasAttributeNS( "http://www.mozilla.org/ns/specialspace/", "special-align")) { d.setAttribute("align", "center"); } </pre> <h3 id=".E6.B3.A8.E8.A8.98" name=".E6.B3.A8.E8.A8.98">注記</h3> <p>{{ DOMAttributeMethods() }}</p> <h3 id=".E4.BB.95.E6.A7.98" name=".E4.BB.95.E6.A7.98">仕様</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>