Add and remove a property named "color":
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"> </script>//from ww w . j ava 2 s .c om <script> $(document).ready(function(){ $("button").click(function(){ let $x = $("div"); $x.prop("color", "EEEEEE"); $x.append("color property value: " + $x.prop("color")); $x.removeProp("color"); $x.append("<br>color property value: " + $x.prop("color")); }); }); </script> </head> <body> <button>Add and remove a property</button><br><br> <div></div> </body> </html>
The removeProp()
method removes a property set by the prop()
method.
To remove HTML attributes like style, id, or checked, use the removeAttr()
method.
$(selector).removeProp(property)
Parameter | Description |
---|---|
property | the name of the property to remove |