blob: e221ac44d9f78a30291e1223d9f80d99a2b69e9b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
---
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>
|