The removeData() is an inbuilt method in jQuery which is used to remove those data which are previously set with the data() method.
Syntax:
$(selector).removeData(args);
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.
Code #1:
In the below code, the data get removed by removeData() method set by the data() method.
<html> <head> </script> <script> <!-- 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"). data("greeting")); }); <!-- click here to remove data from div element --> $("#b2").click(function() { $("div").removeData("greeting"); alert("Greeting is: " + $("div"). data("greeting")); }); }); </script> <style> #b1, #b2 { padding: 10px; margin: 20px; background-color: green; } </style> </head> <body> <button id="b1">Click here to add data to div element</button> <br> <button id="b2">Click here to Remove data from div element</button> <div></div> </body> </html> |
Output:
After attaching the data-

After removing the data-

Recommended Posts:
- jQuery | jQuery.fx.interval Property with example
- jQuery | jQuery.fx.off Property
- jQuery | jQuery.support Property
- jQuery | jquery Property
- jQuery | prepend() with Examples
- jQuery | dblclick() with Examples
- jQuery | offset() with Examples
- jQuery | children() with Examples
- jQuery | Hide/Show, Toggle and Fading methods with Examples
- jQuery | focusin() with Examples
- jQuery | Animation, Slide methods with Examples
- jQuery | change() with Examples
- jQuery | filter() with Examples
- jQuery | height() and innerHeight() with Examples
- jQuery | eq() with Examples
- jQuery | empty() with Examples
- jQuery | not() method with Examples
- jQuery | first() with Examples
- jQuery | parent() & parents() with Examples
- jQuery | noConflict() with Examples
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.


