removeData() Method - Javascript jQuery Method and Property

Javascript examples for jQuery Method and Property:removeData

Description

The removeData() method removes data previously set with the data() method.

Syntax

Parameter RequireDescription
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:

Demo Code

ResultView the demo in separate window

<!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>

Related Tutorials