aboutsummaryrefslogtreecommitdiff
path: root/files/fr/web/api/element/hasattributes/index.md
blob: abd55717775ebf906c84d4b89a43bdd3527cbb34 (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
---
title: element.hasAttributes
slug: Web/API/Element/hasAttributes
tags:
  - API
  - DOM
  - Element
  - Méthode
  - Reference
  - polyfill
translation_of: Web/API/Element/hasAttributes
---
{{ApiRef("DOM")}}

La méthode **`hasAttributes()`**, rattachée à l'interface {{domxref("Element")}}, renvoie une valeur booléenne indiquant si le nœud courant a au moins un attribut ou non.

## Syntaxe

```js
var result = element.hasAttributes();
```

### Valeur de retour

- `result`
  - : contient la valeur de retour `true` ou `false`.

## Exemple

```js
var foo = document.getElementById("foo");
if (foo.hasAttributes()) {
    // faire quelque chose avec 'foo.attributes'
}
```

## Polyfill

```js
;(function(prototype) {
    prototype.hasAttributes = prototype.hasAttributes || function() {
        return (this.attributes.length > 0);
    }
})(Element.prototype);
```

## Spécifications

| Spécification                                                                                                    | Statut                           | Commentaire                                                                                                     |
| ---------------------------------------------------------------------------------------------------------------- | -------------------------------- | --------------------------------------------------------------------------------------------------------------- |
| {{SpecName("DOM WHATWG", "#dom-element-hasattributes", "Element.hasAttributes()")}} | {{Spec2('DOM WHATWG')}} | Déplacé de l'interface {{domxref("Node")}} vers l'interface plus spécialisée {{domxref("Element")}}. |
| {{SpecName('DOM3 Core','#ID-NodeHasAttrs','hasAttributes()')}}                             | {{Spec2('DOM3 Core')}}     | Pas de changement par rapport à {{SpecName("DOM2 Core")}}                                                |
| {{SpecName('DOM2 Core','#ID-NodeHasAttrs','hasAttributes()')}}                             | {{Spec2('DOM2 Core')}}     | Définition initiale, sur l'interface {{domxref("Node")}}.                                                  |

## Compatibilité des navigateurs

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

## Voir aussi

- {{domxref("Element.attributes")}}
- {{domxref("Element.hasAttribute()")}}