From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- .../web/api/element/getattributenames/index.html | 72 ++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 files/ja/web/api/element/getattributenames/index.html (limited to 'files/ja/web/api/element/getattributenames/index.html') diff --git a/files/ja/web/api/element/getattributenames/index.html b/files/ja/web/api/element/getattributenames/index.html new file mode 100644 index 0000000000..0b08900da0 --- /dev/null +++ b/files/ja/web/api/element/getattributenames/index.html @@ -0,0 +1,72 @@ +--- +title: Element.getAttributeNames() +slug: Web/API/Element/getAttributeNames +tags: + - API + - DOM + - Element + - getAttributeNames + - メソッド + - 属性 +translation_of: Web/API/Element/getAttributeNames +--- +
{{APIRef("DOM")}}
+ +

{{domxref("Element")}} インターフェースの getAttributeNames() メソッドは要素の属性の名前を文字列の {{jsxref("Array")}} で返します。要素に属性がない場合は、空の配列を返します。

+ +

getAttributeNames() を {{domxref("Element.getAttribute","getAttribute()")}} と共に使用すると、 {{domxref("Element.attributes")}} にアクセスするよりメモリ効率やパフォーマンスが良くなります。

+ +

構文

+ +
let attributeNames = element.getAttributeNames();
+
+ +

+ +
// 要素の属性に対して反復処理する
+for(let name of element.getAttributeNames()) {
+	let value = element.getAttribute(name);
+	console.log(name, value);
+}
+
+ +

代替モジュール

+ +
if (Element.prototype.getAttributeNames == undefined) {
+  Element.prototype.getAttributeNames = function () {
+    var attributes = this.attributes;
+    var length = attributes.length;
+    var result = new Array(length);
+    for (var i = 0; i < length; i++) {
+      result[i] = attributes[i].name;
+    }
+    return result;
+  };
+}
+ +

仕様書

+ + + + + + + + + + + + + + + + +
仕様書状態備考
{{SpecName("DOM WHATWG", "#dom-element-getattributenames", "Element.getAttributeNames")}}{{Spec2("DOM WHATWG")}}初回定義
+ +

ブラウザーの対応

+ +
+ + +

{{Compat("api.Element.getAttributeNames")}}

+
-- cgit v1.2.3-54-g00ecf