The jQuery removeData method removes the data previously attached to elements. The data is attached by jQuery Data method.
$(selector).removeData(name)
Parameter | Description |
---|---|
name | Optional Specifies the name of data to remove. If no name is given, then the removeData() method will remove all stored data from the selected elements. |
In the below code – first button will attach data to the div while second button will remove the attached data.
<div id="div1"></div>
<button id="button1">Attach Data to Div</button>
<button id="button2">Remove Data from Div</button>
On the second button click event I used jQuery removeData method to remove the attached data from the div.
See the below code.
$("#button1").click(function () {
$("#div1").data("name", "Yogi");
});
$("#button2").click(function () {
$("#div1").removeData("name");
});
Refer the download link: