jQuery removeAttr method with div and button examples

jQuery removeAttr method

You can remove one or more attributes of specified elements by using jQuery removeAttr method. This method is quite simple to use. You have to specify element name like image element, div, paragraph etc. followed by the removeAttr method and provide the attribute to be removed.

The example below shows how to remove attributes from different elements. Let us first look at the syntax of the removeAttr method.

How to use the removeAttr method

The syntax of jQuery removeAttr method is:


Where an element can be an image, a div, a paragraph, table etc.

Note that if you use removeAttr method to remove the attribute(s) of the element, it will change attributes to all matched elements.

jQuery remove attribute with paragraph style example

The example below shows how to remove style attribute in the paragraph by using the removeAttr method of jQuery. The paragraph’s text color is set to be red and font size is 20px. Once the button is clicked, the paragraph’s  style will be removed. Have a look:

jQuery remove attribute

Experience this example online


An example of remove attribute with button

This example shows how to remove CSS from a button. As you click on the button, it will remove style from the CSS-styled button by using the removeAttr method.

Experience this example online


Related reading: jQuery $.css | jQuery add attribute | jQuery html method

Was this article helpful?

Related Articles

Leave A Comment?