jQuery removeData() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
DOM

Definition

.removeData([name|list]) deletes values previously stored with .data() from jQuery’s internal cache (since 1.2.3; bulk keys since 1.7). With no arguments, it clears all cached values.

Syntax

Start with these common calls. Keep them short and readable.

jQuery
$div.data("test1", "VALUE-1")
$div.removeData("test1")          // one key
$div.removeData(["a", "b"])       // bulk (1.7+)
$div.removeData("a b")            // space-separated (1.7+)
$div.removeData()                 // clear all

// HTML data-* attributes are NOT removed
CallWhat it does
removeData()Learn jQuery .removeData(): delete values from jQuery's data cache, one key or all, bulk keys since 1.7, data-* pitfalls, examples, and FAQs.

Load jQuery before your script (CDN or local file), then wrap DOM work in $(function () { ... }) when needed.

Parameters

ParameterDescription
Step 1Select the element(s) that hold jQuery data.
Step 2Pass one key, a list of keys (1.7+), or nothing to clear all.
Step 3Call .removeData(…) — the element stays in the DOM.

Return Value

Return ValueDescription
jQuery objectMost setters and traversing helpers return the jQuery collection so you can chain more methods.
Value / undefinedGetters usually return a value from the first matched element, or undefined when nothing applies.

jQuery Examples

Example 1 — Official Demo: Remove One Key

Store two values, delete test1, confirm test2 remains.

jQuery
var $div = $("#box");
console.log($div.data("test1"));           // undefined
$div.data("test1", "VALUE-1");
$div.data("test2", "VALUE-2");
console.log($div.data("test1"));           // "VALUE-1"
$div.removeData("test1");
console.log($div.data("test1"));           // undefined
console.log($div.data("test2"));           // "VALUE-2"
Try It Yourself

How It Works

  1. Before set. No test1 yet → undefined.
  2. Store two keys. test1 and test2 live in the cache.
  3. Remove one. removeData("test1") deletes only that key.

Example 2 — Clear All Cached Data

Call .removeData() with no arguments to wipe the cache.

jQuery
var $el = $("#card");
$el.data("score", 10).data("level", 2);
$el.removeData();
console.log($el.data("score"));  // undefined
console.log($el.data("level"));  // undefined
Try It Yourself

How It Works

  1. Seed. Two keys are stored on #card.
  2. Clear all. No-arg removeData() empties the cache.
  3. Reads fail. Both keys return undefined.

Example 3 — Bulk Keys (Since 1.7)

Delete several named keys in one call with an array or space-separated string.

jQuery
var $el = $("#panel");
$el.data("a", 1).data("b", 2).data("c", 3);
$el.removeData(["a", "b"]);   // or .removeData("a b")
console.log($el.data("a"));   // undefined
console.log($el.data("b"));   // undefined
console.log($el.data("c"));   // 3
Try It Yourself

How It Works

  1. Three keys. a, b, and c are stored.
  2. Bulk delete. The array lists only a and b.
  3. Those go. Both return undefined.

Frequently Asked Questions

.removeData(name) deletes one value from jQuery's internal data cache on matched elements. With no arguments, it clears all cached values. Returns the jQuery collection for chaining. Available since jQuery 1.2.3.
.data() stores values; .removeData() deletes them from the same cache. Use .data() for plugin state and .removeData() when resetting or destroying a widget.
No. It only clears jQuery's internal cache. data-* attributes stay in the DOM, so a later .data('key') may re-read data-key. Pair with .removeAttr('data-key') when you need both gone.
Yes, since jQuery 1.7. Pass an array — .removeData(['foo', 'bar']) — or a space-separated string — .removeData('foo bar').
.removeData() clears cached values but keeps the element. .remove() deletes the element from the DOM and also cleans up its data and events.
When resetting widget state, clearing stale options, or cleaning up before re-init on the same element. Elements removed with .remove() already lose their cache; detached nodes keep it until you clear it.

Next: .hide() Method

Learn how to hide matched elements without removing them from the DOM.

.hide() Method tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful