English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

HTML DOM removeAttribute() Method

HTML DOM Element Object

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.

Syntax:

element.removeAttribute(attrName)
document.getElementsByTagName("H"1")[0].removeAttribute("class");
Test and See‹/›

Browser Compatibility

All browsers fully support the removeAttribute() method:

Method
removeAttribute()YesYesYesYesYes

Parameter Value

ParameterDescription
attrNameA string representing the name of the attribute to be removed from the element

Technical Details

Return Value:Undefined
DOM Version:DOM 2Level

More Examples

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‹/›

Related References

HTML Tutorial:HTML Attributes

HTML DOM Reference:getAttribute() method

HTML DOM Reference:setAttribute() method

HTML DOM Reference:hasAttribute() method

HTML DOM Element Object