.removeData() in JQuery


Description: Remove a previously-stored piece of data.

  • version added: 1.2.3.removeData( [ name ] )

    nameA string naming the piece of data to delete.

The .removeData() method allows us to remove values that were previously set using .data(). When called with the name of a key, .removeData() deletes that particular value; when called with no arguments, all values are removed.


Set a data store for 2 names then remove one of them.

<!DOCTYPE html>
  div { margin:2px; color:blue; }
  span { color:red; }
  <script src="/scripts/jquery-1.4.js"></script>
	<div>value1 before creation: <span></span></div>
  <div>value1 after creation: <span></span></div>
  <div>value1 after removal: <span></span></div>

  <div>value2 after removal: <span></span></div>

    $("span:eq(0)").text("" + $("div").data("test1"));
    $("div").data("test1", "VALUE-1");
    $("div").data("test2", "VALUE-2");
    $("span:eq(1)").text("" + $("div").data("test1"));
    $("span:eq(2)").text("" + $("div").data("test1"));
    $("span:eq(3)").text("" + $("div").data("test2"));


Leave a Reply

Your email address will not be published. Required fields are marked *