Méthode HTML DOM removeAttribute()
❮ L'objet élémentExemple
Supprimez l'attribut class d'un élément <h1> :
document.getElementsByTagName("H1")[0].removeAttribute("class");
Définition et utilisation
La méthode removeAttribute() supprime l'attribut spécifié d'un élément.
La différence entre cette méthode et la méthode removeAttributeNode() est que la méthode removeAttributeNode() supprime l' objet Attr spécifié , tandis que cette méthode supprime l'attribut avec le nom spécifié . Le résultat sera le même. De plus, cette méthode n'a pas de valeur de retour, tandis que la méthode removeAttributeNode() renvoie l'attribut supprimé, en tant qu'objet Attr.
Astuce : Utilisez la méthode getAttribute() pour renvoyer la valeur d'un attribut d'un élément.
Astuce : Utilisez la méthode setAttribute() pour ajouter un attribut à un élément.
Prise en charge du navigateur
Method | |||||
---|---|---|---|---|---|
removeAttribute() | Yes | Yes | Yes | Yes | Yes |
Syntaxe
element.removeAttribute(attributename)
Valeurs des paramètres
Parameter | Type | Description |
---|---|---|
attributename | String | Required. The name of the attribute you want to remove |
Détails techniques
Valeur de retour : | Aucune valeur de retour |
---|---|
Version DOM | Objet élément de niveau 1 de base |
Plus d'exemples
Exemple
Supprimez l'attribut href d'un élément <a> :
document.getElementById("myAnchor").removeAttribute("href");
Pages connexes
Tutoriel HTML : Attributs HTML
Référence HTML DOM : méthode hasAttribute()
Référence HTML DOM : méthode getAttribute()
Référence HTML DOM : méthode setAttribute()
❮ L'objet élément