Remove the class attribute from an element:
The removeAttribute() method removes an attribute from an element.
- The Difference Between removeAttribute() and removeAttributeNode()
- See Also:
- Tutorial:
- Syntax
- Parameters
- Return Value
- Browser Support
- COLOR PICKER
- Report Error
- Thank You For Helping Us!
- Remove HTML tag attributes
- Except src (img tags) and href (anchor tags)
- Remove All Attributes From an Element in JavaScript
- Link to this section
The Difference Between removeAttribute() and removeAttributeNode()
The removeAttribute() method removes an attribute, and does not have a return value.
The removeAttributeNode() method removes an Attr object, and returns the removed object.
The result will be the same.
See Also:
Tutorial:
Syntax
Parameters
Return Value
Browser Support
element.removeAttribute() is a DOM Level 1 (1998) feature.
It is fully supported in all browsers:
Chrome | Edge | Firefox | Safari | Opera | IE |
Yes | Yes | Yes | Yes | Yes | 9-11 |
COLOR PICKER
Report Error
If you want to report an error, or if you want to make a suggestion, do not hesitate to send us an e-mail:
Thank You For Helping Us!
Your message has been sent to W3Schools.
Top Tutorials
Top References
Top Examples
Get Certified
W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy.
Remove HTML tag attributes
Except src (img tags) and href (anchor tags)
table style="width: 300px; text-align: center;" border="1" cellpadding="5"> tbody> tr> th width="75">strong>Name strong> th> th colspan="2">span style="font-weight: bold;">Telephone span> th> tr> tr> td>John td> td>a href="tel:0123456785">0123 456 785 a> td> td>img src="images/check.gif" alt="checked" /> td> tr> tbody> table>
table> tbody> tr> th>strong>Name strong> th> th>span>Telephone span> th> tr> tr> td>John td> td>a href="tel:0123456785">0123 456 785 a> td> td>img src="images/check.gif"/> td> tr> tbody> table>
This option will leave you the HTML structure but it will remove every attribute (classes, styles and other properties).
Removes classes, inline styles and other tag attributes except the src attribute of image tags and href attributes of anchor tags. We have separated these features because there are individual options to remove the links and images from the HTML source. We decided to implement this feature this way because people never want to end up with a stripped element or a link tag without reference in their code.
Remove All Attributes From an Element in JavaScript
This JavaScript function will accept a given HTML element and remove all of its attributes:
const removeAttributes = (element) => < while (element.attributes.length > 0) < element.removeAttribute(element.attributes[0].name); > >;
If you don’t want to use a while loop, here is an alternative removeAttributes function:
const removeAttributes = (element) => < for (let i = 0; i element.attributes.length; i++) < element.removeAttribute(element.attributes[i].name); > >;
Regardless of which variant of the removeAttributes function you chose, here is some example usage:
const element = document.getElementById(`example`); removeAttributes(element);
In the above example, an element with an ID of example is stripped of all its attributes.
Link to this section
I’ve found this to be an exceedingly simple yet exceedingly useful function, and I hope it helped you out as well!