jQuery Remove Property: Main Tips
- The jQuery
.removeProp()
removes properties added using the .prop() method. - Removing native properties of objects is not recommended: delete only custom ones. Set the native ones to
false
with.prop()
instead.
Using .removeProp()
The .removeProp()
method makes jQuery remove property added using .prop() on a selected element. In the example below, you can see jQuery remove CSS property from a <p>
element:
Example
$("button").click(() => {
$("p").prop("secret", "FF0000");
$("p").removeProp("secret");
});
Follow this syntax to make jQuery remove property:
$("selector").removeProp(property);
The name of the property
is always defined in a string.
Remember: do not make jQuery remove disabled, checked, selected, and other native properties. You won't be able to re-add them again.