removeAttribute() in javascript

removeAttribute() method in javascript

removeAttribute() method is used to remove an attribute from the specified element.

removeAttribute() doesn't returns anything.

Example - Remove attribute from an element

Try Yourself

Example Explanation

  • In the above example the button contains the following attributes style, id, onclick.
  • When the button is clicked, the button element (document.getElementById('idBtn')) is stored in elem variable.
  • Next by using the removeAttribute method style attribute is removed from the button element (elem.removeAttribute("style")). So the button background color will be removed.
  • Then using alert method we are displaying the button element (alert(elem.outerHTML)), in here we can see the style attribute is removed from the button.