jQuery removeData() method – Used to remove attached data to elements

jQuery removeData() method – Used to remove attached data to elements

The jQuery removeData method removes the data previously attached to elements. The data is attached by jQuery Data method.

Syntax of jQuery removeData 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.

Example: jQuery removeData Method

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:

DOWNLOAD

SHARE THIS ARTICLE

  • linkedin
  • reddit
yogihosting

ABOUT THE AUTHOR

I hope you enjoyed reading this tutorial. If it helped you then consider buying a cup of coffee for me. This will help me in writing more such good tutorials for the readers. Thank you. Buy Me A Coffee donate