
- jQuery - Home
- jQuery - Roadmap
- jQuery - Overview
- jQuery - Basics
- jQuery - Syntax
- jQuery - Selectors
- jQuery - Events
- jQuery - Attributes
- jQuery - AJAX
- jQuery CSS Manipulation
- jQuery - CSS Classes
- jQuery - Dimensions
- jQuery - CSS Properties
- jQuery Traversing
- jQuery - Traversing
- jQuery - Traversing Ancestors
- jQuery - Traversing Descendants
- jQuery References
- jQuery - Selectors
- jQuery - Events
- jQuery - Effects
- jQuery - HTML/CSS
- jQuery - Traversing
- jQuery - Miscellaneous
- jQuery - Properties
- jQuery - Utilities
- jQuery Plugins
- jQuery - Plugins
- jQuery - PagePiling.js
- jQuery - Flickerplate.js
- jQuery - Multiscroll.js
- jQuery - Slidebar.js
- jQuery - Rowgrid.js
- jQuery - Alertify.js
- jQuery - Progressbar.js
- jQuery - Slideshow.js
- jQuery - Drawsvg.js
- jQuery - Tagsort.js
- jQuery - LogosDistort.js
- jQuery - Filer.js
- jQuery - Whatsnearby.js
- jQuery - Checkout.js
- jQuery - Blockrain.js
- jQuery - Producttour.js
- jQuery - Megadropdown.js
- jQuery - Weather.js
jQuery removeAttr() Method
The removeAttr() method in jQuery is used to remove one or more attributes from selected elements in the DOM.
This method accepts a parameter named âattributeâ which specifies the name of the attribute of an HTML element to remove.
Syntax
Following is the syntax of removeAttr() method in jQuery −
$(selector).removeAttr(attribute)
Parameters
This method accepts the following parameters −
- attribute: A string representing the name of the attribute to remove.
Note: To remove multiple attributes, we need to separate the attribute names with a space.
Example 1
In the following example, we are using the removeAttr() method to remove the âstyleâ attribute from the <div> element −
<html> <head> <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> <script> $(document).ready(function(){ $('button').click(function(){ $('div').removeAttr('style'); }); }); </script> </head> <body> <div style="background-color: yellow; width:220px; border: 2px solid black;">This is a div with some styling.</div> <button>Remove Style Attribute</button> </body> </html>
When we click the button, the styling for the <div> element will be removed.
Example 2
In this example, we are removing multiple attributes from an âinputâ element −
<html> <head> <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> <script> $(document).ready(function(){ $('button').click(function(){ $('input').removeAttr('readonly placeholder'); }); }); </script> </head> <body> <input type="text" readonly placeholder="Enter your name"> <button>Remove Attributes</button> </body> </html>
When we click the button, it removes multiple attributes (âreadonlyâ and âplaceholderâ) from the âinputâ element.