Javascript examples for jQuery Method and Property:removeData
The removeData() method removes data previously set with the data() method.
Parameter | Require | Description |
---|---|---|
name | Optional. | name of data to remove. |
If no name is specified, this method will remove all stored data from the selected elements
The following code shows how to Remove previously attached data from a <div> element:
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script> $(document).ready(function(){ $("#btn1").click(function(){ $("div").data("greeting", "Hello World"); console.log("Greeting is: " + $("div").data("greeting")); });/*from w w w .ja v a 2 s . c om*/ $("#btn2").click(function(){ $("div").removeData("greeting"); console.log("Greeting is: " + $("div").data("greeting")); }); }); </script> </head> <body> <button id="btn1">Attach data to div element</button><br> <button id="btn2">Remove data attached to div element</button> <div></div> </body> </html>