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 links to DEMO / DOWNLOAD Codes:

DEMO DOWNLOAD

Share this article -

yogihosting

ABOUT THE AUTHOR

This article has been written by the Technical Staff of YogiHosting. Check out other articles on "ASP.NET Core, jQuery, EF Core, SEO, jQuery, HTML" and more.