# removeAttribute()

### Introduction to JavaScript `removeAttribute()` method

The `removeAttribute()` removes an attribute with a specified name from an element:

```css
element.removeAttribute(name);
Code language: CSS (css)
```

#### Parameters

The `removeAttribute()` accepts an argument which is the name of the attribute that you want to remove. If the attribute does not exist, the `removeAttribute()`  method wil not raise an error.

#### Return value

The `removeAttribute()` returns a value of `undefined`.

#### Usage notes

HTML elements have some attributes which are Boolean attributes. To set `false` to the Boolean attributes, you cannot simply use the [`setAttribute()`](https://www.javascripttutorial.net/javascript-dom/javascript-setattribute/) method, but you have to remove the attribute entirely using the `removeAttribute()` method.

For example, the values of the `disabled` attributes are `true` in the following cases:

```xml
<button disabled>Save Draft</button>
<button disabled="">Save</button>
<button disabled="disabled">Cancel</button>
Code language: HTML, XML (xml)
```

Similarly, the values of the following `readonly` attributes are `true`:

```xml
<input type="text" readonly>
<textarea type="text" readonly="">
<textarea type="text" readonly="readonly">
Code language: HTML, XML (xml)
```

### JavaScript `removeAttribute()` example

The following example uses the `removeAttribute()` method to remove the `target` attribute from the link element with the id `js`:

```xml
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>JS removeAttribute() Demo</title>
</head>
<body>
    <a href="https://www.javascripttutorial.net" 
       target="_blank" 
       id="js">JavaScript Tutorial</a>

    <script>
        let link = document.querySelector('#js');
        if (link) {
            link.removeAttribute('target');
        }
    </script>
</body>
</html>
Code language: HTML, XML (xml)
```

How it works:

* Select the link element with id `js` using the `querySelector()` method.
* Remove the `target` attribute by calling the `removeAttribute()` on the selected link element.

### Summary

* Use the `removeAttribute()` to remove an attribute from a specified element.
* Setting the value of a Boolean attribute to `false` will not work; use the `removeAttribute()` method instead.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://edrus.gitbook.io/mt-it/2nd-month/week-6/dom-document-object-model/working-with-attributes/removeattribute.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
