jQuery removeData() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Utilities

Definition

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
CallWhat it does
jQueryLearn 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

ParameterDescription
Step 1Get a native element: $("#box")[0] or document.getElementById("box").
Step 2Store data first with $.data(el, "key", value) (or .data()).
Step 3Call $.removeData(el, "key") for one key, or $.removeData(el) to clear all.

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

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"
Try It Yourself

How It Works

  1. Unwrap. $("div")[0] is the raw DOM element the static API needs.
  2. Store two keys. $.data writes test1 and test2 into the cache.
  3. Remove one. $.removeData(div, "test1") deletes only that name.

Example 2 — Clear All Data (No Name)

Call $.removeData(el) with only the element to wipe the store.

jQuery
var el = document.getElementById("box");

$.data(el, "a", 1);
$.data(el, "b", 2);
$.removeData(el);

console.log($.data(el, "a")); // undefined
console.log($.data(el, "b")); // undefined
Try It Yourself

How It Works

  1. Seed. Two keys (a, b) are stored on the element.
  2. No name. $.removeData(el) clears every cached value for that node.
  3. 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
Try It Yourself

How It Works

  1. Seed from markup. .data("score") can pull data-score into the cache.
  2. Clear cache. $.removeData(el, "score") drops the internal key only.
  3. 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.

Next: parseHTML() Method

Show, add, or replace the function queue on a DOM element.

parseHTML() 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.

9 people found this page helpful