jQuery | removeData() with Examples

The removeData() is an inbuilt method in jQuery which is used to remove those data which are previously set with the data() method.


Here “selector” is the selected element whose previously set data get removed.
Parameter: It accepts an optional parameter “args” which specifies the name of the data to remove for the selected element.
Return Value : It returns the selected element with removed data.

jQuery code to show the working of removeData() method:

Code #1:
In the below code, the data get removed by removeData() method set by the data() method.





        <!-- working of remove data method -->
        $(document).ready(function() {
            <!-- click here to add data to div element -->
            $("#b1").click(function() {
                $("div").data("greeting", "Hello Everyone !");
                alert("GeeksforGeeks says : " + $("div").
            <!-- click here to remove data from div element -->
            $("#b2").click(function() {
                alert("Greeting is: " + $("div").
        #b2 {
            padding: 10px;
            margin: 20px;
            background-color: green;
    <button id="b1">Click here to add data to 
                     div element</button>
    <button id="b2">Click here to Remove data 
                    from div element</button>


After attaching the data-

After removing the data-


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.