HTML | DOM removeAttribute() Method
The DOM removeAttribute() method is used to remove an attribute with specified name from the element. It is similar to removeAttributeNode() method but the difference is that the removeAttributeNode method is used to remove the specified attribute object, but on the other hand removeAttribute removes the attribute with the specified name.
Syntax:
element.removeAttribute(name)
Where name is the string which specifies the name of the attribute to remove from the element. It is the required field.
Example:
<!DOCTYPE html> < html > < head > < title > HTML DOM removeAttribute Method </ title > < style > .gfg { color: green; } </ style > </ head > < body style = "text-align: center;" > < h1 style = "color:green;" > GeeksforGeeks </ h1 > < h2 > DOM removeAttribute Method </ h2 > < p id = "p" class = "gfg" > A computer science portal for geeks. </ p > < button onclick = "Geeks()" > Click Here! </ button > < script > function Geeks() { //Remove class attributes from 'p' element. document.getElementById( "p").removeAttribute("class"); } </ script > </ body > </ html > |
Output:
Before click on the button:
After click on the button:
Supported Browsers: The browser supported by removeAttribute() method are listed below:
- Google Chrome
- Internet Explorer
- Firefox
- Opera
- Safari
Recommended Posts:
- p5.js | removeAttribute() Function
- HTML | DOM contains() Method
- HTML | DOM setAttributeNode() Method
- HTML | DOM History go() Method
- HTML | method Attribute
- HTML | DOM createAttribute() Method
- HTML | DOM fullscreenEnabled() Method
- HTML | DOM querySelectorAll() Method
- HTML | DOM querySelector() Method
- HTML | DOM close() Method
- HTML | DOM insertBefore() Method
- HTML | DOM scrollIntoView() Method
- HTML | DOM Select add Method
- HTML | DOM removeChild() Method
- HTML | DOM write() Method
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.