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 | 116 +++++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 files/fr/web/api/element/getattributenames/index.html (limited to 'files/fr/web/api/element/getattributenames') diff --git a/files/fr/web/api/element/getattributenames/index.html b/files/fr/web/api/element/getattributenames/index.html new file mode 100644 index 0000000000..8aa41d44ad --- /dev/null +++ b/files/fr/web/api/element/getattributenames/index.html @@ -0,0 +1,116 @@ +--- +title: Element.getAttributeNames() +slug: Web/API/Element/getAttributeNames +tags: + - API + - Attributs + - DOM + - Element + - Méthodes +translation_of: Web/API/Element/getAttributeNames +--- +

{{APIRef("DOM")}}

+ +

Element.getAttributeNames() renvoie les noms des attributs de l'élément sous la forme d'un {{jsxref("Array")}} (tableau) de chaînes de caractères. Si l'élément n'a pas d'attributs, il retourne un tableau vide.

+ +

L'utilisation de getAttributeNames() complété par {{domxref("Element.getAttribute","getAttribute()")}}, est une alternative efficiente et performante pour l'accès à {{domxref("Element.attributes")}}.

+ +

Syntaxe

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

Exemple

+ +
// Itérer sur les attributs de l'élément
+for(let name of element.getAttributeNames())
+{
+	let value = element.getAttribute(name);
+	console.log(name, value);
+}
+
+ +

Polyfill

+ +
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;
+  };
+}
+ +

Spécifications

+ + + + + + + + + + + + + + +
SpécificationStatutCommentaire
{{SpecName("DOM WHATWG", "#dom-element-getattributenames", "Element.getAttributeNames")}}{{Spec2("DOM WHATWG")}}Définition initiale.
+ +

Compatibilité des navigateurs

+ +
{{CompatibilityTable}}
+ +
+ + + + + + + + + + + + + + + + + + + +
FonctionnalitéChromeFirefox (Gecko)Internet ExplorerOperaSafari (WebKit)
Basic support{{CompatChrome(61)}}{{CompatGeckoDesktop(45)}}{{CompatNo}}{{CompatOpera(48)}}{{CompatSafari(9)}}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
FonctionnalitéAndroid WebviewChrome for AndroidFirefox Mobile (Gecko)Firefox OSIE MobileOpera MobileSafari Mobile
Basic support{{CompatChrome(61)}}{{CompatChrome(61)}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}{{CompatOperaMobile(48)}}{{CompatUnknown}}
+
-- cgit v1.2.3-54-g00ecf