jQuery removeAttr() method

The jQuery removeAttr() method can be used to remove the attributes from the selected elements. You can remove single or multiple attributes using the method.

jQuery removeAttr() method

Syntax of jQuery removeAttr() Method

The syntax of the method is given below.

Syntax
$(selector).removeAttr(attribute)

Description of the Parameters

There are two parameters whose descriptions are given below.

Parameter Name Description
selector It is used to select the elements to remove the attributes. You can use the tag name, class name, or id of the elements to select.
attribute Specify the attributes of the element to remove. You can find the examples below to remove single as well as the multiple attributes.

Let’s make it more clear with the examples given below.

jQuery removeAttr() Method Remove Single Attribute

To explain the removal of single attributes, let’s take an example given below. It contains a paragraph with a single class attribute to remove. A button element is using here to remove attribute on click.

Example

Test it Live

Output

This is my paragraph.

The class attribute applies the border and padding to the paragraph. Click the button given above to see the difference if the class gets removed.

Remove Multiple Attributes Using The Method

Similarly, the method can also remove multiple attributes from the selected elements.

The syntax for removing multiple attributes is given below.

Syntax

Syntax
$(selector).removeAttr(attribute1 attribute2 attribute3…attributeN)

the above syntax contains the same parameters described above. You have to use only the multiple attributes as the parameter.

The below example contains the paragraph with multiple attributes class, id, and style. You have to remove these attributes using the jQuery removeAttr() method.

Example

Test it Live

Output


This is my paragraph with multiple attributes.

Click the button above to remove the mentioned attributes as the parameters of the method. When you check the attributes of the elements, you can find them gets removed from the element.

I hope you like this tutorial on jQuery removeAttr() method. If you have any queries regarding the tutorial, please comment below.

References