The jQuery removeProp() method can be used to remove the property of the selected elements. It can remove single or multiple properties from the elements you select.
Syntax
The syntax of the method is given below.
Description of the Parameters
There are two parameters whose descriptions are given below.
Parameter Name | Description |
---|---|
selector | You have to use a selector to select the elements and remove the properties. You can use the tag name, class name, or id of the elements to select. |
property | Specify the property of the element to remove. |
Let’s find out the uses with the examples given below.
jQuery removeProp() Method Remove Single Property
If you want to remove a single property, you have to use the example given below. It contains a paragraph and a button element. The example uses the button click event to remove the property.
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
<script> $(document).ready(function(){ $('.mybtn').click(function(){ $( ".mypara" ).removeProp("class"); }); }); </script> <style> .mypara{ padding:10px; border:1px solid #ccc; } </style> <button type="button" class="mybtn">Click to Remove Property</button> <p class="mypara">This is my paragraph.</p> |
Output
This is my paragraph.
The property in the class attribute applies the border and padding to the paragraph. When you click the button given above, you can find the difference if the class gets removed.
You may also like to read
I hope you like this tutorial on jQuery removeProp() method. If you have any queries regarding the tutorial, please comment below.
References