Wednesday, July 29, 2026
HomeLanguagesJavascriptjQuery | removeData() with Examples

jQuery | removeData() with Examples

The removeData() is an inbuilt method in jQuery which is used to remove those data which are previously set with the data() method.
Syntax:

$(selector).removeData(args);

Here “selector” is the selected element whose previously set data get removed.
Parameter: It accepts an optional parameter “args” which specifies the name of the data to remove for the selected element.
Return Value : It returns the selected element with removed data.

jQuery code to show the working of removeData() method:
Code #1:
In the below code, the data get removed by removeData() method set by the data() method.




<html>
  
<head>
    </script>
    <script>
        <!-- working of remove data method -->
        $(document).ready(function() {
            <!-- click here to add data to div element -->
            $("#b1").click(function() {
                $("div").data("greeting", "Hello Everyone !");
                alert("neveropen says : " + $("div").
                         data("greeting"));
            });
            <!-- click here to remove data from div element -->
            $("#b2").click(function() {
                $("div").removeData("greeting");
                alert("Greeting is: " + $("div").
                        data("greeting"));
            });
        });
    </script>
    <style>
        #b1,
        #b2 {
            padding: 10px;
            margin: 20px;
            background-color: green;
        }
    </style>
</head>
  
<body>
    <button id="b1">Click here to add data to 
                     div element</button>
    <br>
    <button id="b2">Click here to Remove data 
                    from div element</button>
    <div></div>
</body>
  
</html>


Output:
After attaching the data-

After removing the data-

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

2 COMMENTS

Most Popular

Dominic
32520 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6903 POSTS0 COMMENTS
Nicole Veronica
12017 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12115 POSTS0 COMMENTS
Shaida Kate Naidoo
7023 POSTS0 COMMENTS
Ted Musemwa
7265 POSTS0 COMMENTS
Thapelo Manthata
6981 POSTS0 COMMENTS
Umr Jansen
6973 POSTS0 COMMENTS