jQuery | removeProp() with Examples

The removeProp() method is an inbuilt method in jQuery which is used to remove the property set by the prop() method. The prop() method is used to add property to a selected element.

Syntax:

$(selector).removeProp(property)

Parameter: This method accepts single parameter property which is mandatory. It is used to specify the name of the property which needs to remove.

Return Value: This method returns the selected element with the specified property removed.

Below example illustrates the removeProp() method in jQuery:

Example:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
    <head>
        <title>The removeProp Method</title>
        <script src=
        </script>
          
        <!-- jQuery code to show the working of this method -->
        <script>
            $(document).ready(function() {
                $("button").click(function() {
                    var $GFG = $("div");
                    $GFG.prop("color", "green");
                    $GFG.append("The value of color: "
                                     + $GFG.prop("color"));
                    $GFG.removeProp("color");
                    $GFG.append("<br>The value of color after removeProp: " 
                                            + $GFG.prop("color") + "<br>");
                });
            });
        </script>
        <style>
            div {
                width: 400px;
                min-height: 60px;
                padding: 15px;
                border: 2px solid green;
                margin-bottom: 10px;
            }
        </style>
    </head>
    <body>
       
        <div></div>
        <!-- click on this button -->
        <button>Click Here!</button>
        <br>
        <br>
    </body>
</html>

chevron_right


Output:
removeprop method



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.