# how to remove an attribute from the element using JavaScript

By Atta Ur Rehman Shah (https://attacomsian.com/about). Published Aug 12, 2020, updated Sep 23, 2021. Topics: JavaScript.
Canonical URL: https://attacomsian.com/blog/javascript-dom-remove-an-attribute-from-the-element

> Learn how to remove an attribute from an HTML element using the removeAttribute() method in JavaScript.


To remove an attribute from an HTML element, you can use the `removeAttribute()` method. This method removes the specified attribute from the element.

Let us say that you have got the following anchor link:

```html
<a href="http://example.com" title="Go Back" data-role="self">Click Me</a>
```

Now you want to remove the `title` attribute from the above `<a>` tag. 

You can use the following code snippet:

```javascript
const anchor = document.querySelector('a');

anchor.removeAttribute('title');
```

The `removeAttribute()` also works for HTML5 `data-*` attributes. For example, to remove the `data-role` attribute from the anchor link, you can use the following code:

```javascript
const anchor = document.querySelector('a');

anchor.removeAttribute('data-role');
```

The `removeAttribute()` method works in all modern browsers, and IE8 and above.
