English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
removeAttribute()The method removes the attribute with the specified name from the element.
Note:Since removeAttribute() does not return a value, it cannot be chained together to delete multiple attributes at once.
UsagegetAttribute()The method can return the attribute value of the element.
UsagesetAttribute()The method can add new attributes or change the value of existing attributes on the element.
element.removeAttribute(attrName)
document.getElementsByTagName("H"1")[0].removeAttribute("class");Test and See‹/›
All browsers fully support the removeAttribute() method:
Method | |||||
removeAttribute() | Yes | Yes | Yes | Yes | Yes |
Parameter | Description |
---|---|
attrName | A string representing the name of the attribute to be removed from the element |
Return Value: | Undefined |
---|---|
DOM Version: | DOM 2Level |
Find out if the anchor element has the href attribute. If href exists, use removeAttribute to delete the href attribute:
var a = document.getElementById("myLink"); if (a.hasAttribute("href")) { a.removeAttribute("href"); }Test and See‹/›
HTML Tutorial:HTML Attributes
HTML DOM Reference:getAttribute() method
HTML DOM Reference:setAttribute() method
HTML DOM Reference:hasAttribute() method