jQuery.removeData(element [, name]) (alias $.removeData) deletes values previously set with jQuery.data() from a DOM element (since jQuery 1.2.3). With a name, one key is removed; without a name, the whole store for that element is cleared.
Syntax
Start with these common calls. Keep them short and readable.
jQuery
$.removeData(element, name) → delete one key
$.removeData(element) → clear all keys
$.data(el, "test1", "VALUE-1");
$.removeData(el, "test1");
$.data(el, "test1"); // undefined
// Returns undefined — not chainable
Call
What it does
jQuery
Learn jQuery.removeData(): delete one key or clear all jQuery data on a DOM element, pair with jQuery.data(), vs .removeData() and data-* attributes, examples, pitfalls, and FAQs.
Load jQuery before your script (CDN or local file), then wrap DOM work in $(function () { ... }) when needed.
Parameters
Parameter
Description
Step 1
Get a native element: $("#box")[0] or document.getElementById("box").
Step 2
Store data first with $.data(el, "key", value) (or .data()).
Step 3
Call $.removeData(el, "key") for one key, or $.removeData(el) to clear all.
Return Value
Return Value
Description
jQuery object
Most setters and traversing helpers return the jQuery collection so you can chain more methods.
Value / undefined
Getters usually return a value from the first matched element, or undefined when nothing applies.
jQuery Examples
Example 1 — Official Demo: Remove One Key
Set test1 and test2, then remove only test1.
jQuery
var div = $("div")[0];
$.data(div, "test1", "VALUE-1");
$.data(div, "test2", "VALUE-2");
$.removeData(div, "test1");
console.log($.data(div, "test1")); // undefined
console.log($.data(div, "test2")); // "VALUE-2"
No name.$.removeData(el) clears every cached value for that node.
Reads fail. Both keys return undefined afterward.
Example 3 — Cache Cleared, data-* Remains
Removing cache does not delete the HTML attribute.
jQuery
// <div id="x" data-score="10"></div>
var el = $("#x")[0];
$("#x").data("score"); // 10 (from attribute into cache)
$.removeData(el, "score");
console.log($("#x").attr("data-score")); // "10" — still there
console.log($("#x").data("score")); // may become 10 again from attr
Seed from markup..data("score") can pull data-score into the cache.
Clear cache.$.removeData(el, "score") drops the internal key only.
Attribute stays..attr("data-score") still returns "10".
Frequently Asked Questions
jQuery.removeData(element [, name]) deletes previously stored jQuery data from a DOM element. With a name, only that key is removed. With no name, all values for that element are removed. It returns undefined. Added in jQuery 1.2.3.
Same cache, different call shape. jQuery.removeData(el, key) takes a raw DOM element and is not chainable. .removeData() is called on a jQuery collection, is chainable, and (since 1.7) can take an array or space-separated list of keys. Official docs recommend .removeData() for everyday code.
No. It only clears jQuery’s internal cache. Attributes like data-test1 stay in the markup. A later $(el).data("test1") may re-read the attribute into the cache. Use .removeAttr("data-test1") as well when you need the attribute gone.
jQuery.removeData(element) with no name clears the entire data store for that element (all keys set with jQuery.data / .data that live in the cache).
The API returns undefined. Unlike .removeData(), you cannot chain further jQuery methods off the static call.
When you already hold a raw DOM node (for example div = $("div")[0]) or are following official utility demos that pair jQuery.data with jQuery.removeData. New UI code should prefer .removeData() on a collection.