diff options
Diffstat (limited to 'files/fr/web/api/element/getattributenames/index.md')
-rw-r--r-- | files/fr/web/api/element/getattributenames/index.md | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/files/fr/web/api/element/getattributenames/index.md b/files/fr/web/api/element/getattributenames/index.md new file mode 100644 index 0000000000..d99f4465fe --- /dev/null +++ b/files/fr/web/api/element/getattributenames/index.md @@ -0,0 +1,66 @@ +--- +title: Element.getAttributeNames() +slug: Web/API/Element/getAttributeNames +tags: + - API + - Attributs + - DOM + - Element + - Méthodes +translation_of: Web/API/Element/getAttributeNames +--- +<p>{{APIRef("DOM")}}</p> + +<p><code>Element.getAttributeNames()</code> renvoie les noms des attributs de l'élément sous la forme d'un {{jsxref("Array")}} (<em>tableau</em>) de chaînes de caractères. Si l'élément n'a pas d'attributs, il retourne un tableau vide.</p> + +<p>L'utilisation de <code>getAttributeNames()</code> complété par {{domxref("Element.getAttribute","getAttribute()")}}, est une alternative efficiente et performante pour l'accès à {{domxref("Element.attributes")}}.</p> + +<h2 id="Syntax">Syntaxe</h2> + +<pre class="syntaxbox"><em>let attributeNames</em> = element.getAttributeNames(); +</pre> + +<h2 id="Example">Exemple</h2> + +<pre class="brush:js">// Itérer sur les attributs de l'élément +for(let name of element.getAttributeNames()) +{ + let value = element.getAttribute(name); + console.log(name, value); +} +</pre> + +<h2 id="Polyfill">Polyfill</h2> + +<pre class="brush: html">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; + }; +}</pre> + +<h2 id="Spécifications">Spécifications</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Spécification</th> + <th scope="col">Statut</th> + <th scope="col">Commentaire</th> + </tr> + <tr> + <td>{{SpecName("DOM WHATWG", "#dom-element-getattributenames", "Element.getAttributeNames")}}</td> + <td>{{Spec2("DOM WHATWG")}}</td> + <td>Définition initiale.</td> + </tr> + </tbody> +</table> + +<h2 id="Compatibilité_des_navigateurs">Compatibilité des navigateurs</h2> + +<p>{{Compat("api.Element.getAttributeNames")}}</p> |