--- title: Element.hasAttributes() slug: Web/API/Element/hasAttributes tags: - API - DOM - Element - Method - Reference - メソッド translation_of: Web/API/Element/hasAttributes --- <div>{{ApiRef("DOM")}}</div> <p> <strong><code>hasAttributes()</code></strong> は {{domxref("Element")}} インターフェイスのメソッドで、現在の要素が属性を持っているか否かを {{jsxref("Boolean")}} で返します。</p> <h2 id="Syntax" name="Syntax">構文</h2> <pre class="syntaxbox">var <var>result</var> = <var>element</var>.hasAttributes();</pre> <h3 id="Return_value" name="Return_value">返値</h3> <dl> <dt><code><var>result</var></code></dt> <dd>返値を <code>true</code> または <code>false</code> で保持します。</dd> </dl> <h2 id="Example" name="Example">例</h2> <pre class="brush:js">let foo = document.getElementById('foo'); if (foo.hasAttributes()) { // Do something with 'foo.attributes' } </pre> <h2 id="Polyfill" name="Polyfill">ポリフィル</h2> <pre class="brush:js">;(function(prototype) { prototype.hasAttributes = prototype.hasAttributes || function() { return (this.attributes.length > 0); } })(Element.prototype); </pre> <h2 id="Specifications" name="Specifications">仕様書</h2> <table class="standard-table"> <thead> <tr> <th scope="col">仕様書</th> <th scope="col">状態</th> <th scope="col">備考</th> </tr> </thead> <tbody> <tr> <td>{{SpecName("DOM WHATWG", "#dom-element-hasattributes", "Element.hasAttributes()")}}</td> <td>{{Spec2('DOM WHATWG')}}</td> <td> {{domxref("Node")}} インターフェイスからもっと具体的な {{domxref("Element")}} インターフェイスへ移動した</td> </tr> <tr> <td>{{SpecName('DOM3 Core','#ID-NodeHasAttrs','hasAttributes()')}}</td> <td>{{Spec2('DOM3 Core')}}</td> <td> {{SpecName("DOM2 Core")}} から変更なし</td> </tr> <tr> <td>{{SpecName('DOM2 Core','#ID-NodeHasAttrs','hasAttributes()')}}</td> <td>{{Spec2('DOM2 Core')}}</td> <td> {{domxref("Node")}} インターフェイス上で初回定義</td> </tr> </tbody> </table> <h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザーの互換性</h2> <div class="hidden">このページの互換性一覧表は構造化データから生成されています。データに協力していただけるのであれば、 <a class="external" href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> をチェックアウトしてプルリクエストを送信してください。</div> <p>{{Compat("api.Element.hasAttributes")}}</p> <h2 id="See_also" name="See_also">関連情報</h2> <ul> <li>{{domxref("Element.attributes")}}</li> <li>{{domxref("Element.hasAttribute()")}}</li> </ul>