jQuery .removeData() Method

Beginner
⏱️ 11 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Element data

What You’ll Learn

The .removeData() method deletes values from jQuery’s internal data cache on matched elements — the cleanup counterpart to .data(). This tutorial covers single-key removal, clearing all cached data, bulk deletion with arrays since 1.7, the difference from HTML data-* attributes, comparisons with jQuery.removeData(), the official demo, and five try-it labs.

01

One key

By name

02

All data

No args

03

Bulk

Since 1.7

04

vs .data()

Pair API

05

Cache only

Not attrs

06

Since 1.2.3

Core API

Introduction

This page covers the collection method .removeData() (same API as api.jquery.com/removeData). The low-level static jQuery.removeData() utility is documented under Utilities.

jQuery lets you attach arbitrary JavaScript values to DOM elements with .data() — plugin options, cached calculations, widget state, and more. When that state is no longer needed, .removeData() clears it from jQuery’s internal cache without removing the element from the page.

Available since jQuery 1.2.3, .removeData() accepts an optional key name. Pass a string to delete one value; call with no arguments to wipe the entire cache on each matched element. Since jQuery 1.7, pass an array of keys or a space-separated string to delete several values in one call.

Important: .removeData() does not remove HTML data-* attributes. A later .data("key") call may read the attribute again. Pair with .removeAttr() when you need both the cache and the attribute gone. Browse the jQuery DOM hub for related methods.

Understanding the .removeData() Method

.removeData( [name] ) operates on jQuery’s private data store attached to DOM nodes — the same store that .data() reads and writes. Deleting a key returns undefined on subsequent .data("key") calls unless a matching data-key HTML attribute still exists on the element.

The method returns the jQuery collection, so you can chain further calls on the same elements. It does not trigger change events and does not alter the visible DOM unless your application logic depends on the removed values.

💡
Beginner Tip

The official jQuery demo sets test1 and test2 with .data(), then calls .removeData("test1"). test1 becomes undefined while test2 still reads "VALUE-2" — only the named key is deleted.

📝 Syntax

jQuery .removeData() supports three forms:

Remove one key — since 1.2.3

jQuery
.removeData( name )
  • name — string naming the cached value to delete.
  • Other keys on the same element are untouched.

Remove multiple keys — since 1.7

jQuery
.removeData( [ list ] )

// Array of keys
.removeData( [ "foo", "bar" ] )

// Space-separated string
.removeData( "foo bar" )

Remove all cached data

jQuery
.removeData()
  • No arguments clears every value in jQuery’s internal cache for matched elements.
  • HTML data-* attributes are still not removed.

Official removeData pattern

jQuery
$( "div" ).data( "test1", "VALUE-1" );
$( "div" ).data( "test2", "VALUE-2" );
$( "div" ).removeData( "test1" );

⚡ Quick Reference

GoalCode
Delete one cached key$("#el").removeData("widget")
Clear entire cache$("#el").removeData()
Delete multiple keys (1.7+)$("#el").removeData(["a", "b"])
Space-separated keys$("#el").removeData("a b")
Store data first$("#el").data("key", value)
Also remove data-* attr$("#el").removeAttr("data-key")

📋 .removeData() vs .data() vs jQuery.removeData() vs .removeAttr()

Four related data APIs — know what each one actually clears.

.removeData()
delete cache

Remove values from jQuery’s internal store on a collection — returns jQuery object

.data()
get / set

Read or write cached values; also reads data-* attributes on first access

jQuery.removeData()
static

Low-level utility — pass a native DOM element, not a jQuery object

.removeAttr()
HTML attr

Removes data-key from the DOM markup — pair with removeData for full cleanup

Examples Gallery

Example 1 follows the official jQuery API documentation. Examples 2–5 cover clearing all data, bulk key removal, widget reset patterns, and the data-* attribute pitfall. Use DevTools or the Try-it links to run each snippet in the browser.

📚 Getting Started

Official jQuery demo and cache cleanup fundamentals.

Example 1 — Official Demo: Remove One Key

Set two data keys on a <div>, remove test1, and observe that test2 remains.

jQuery
$( "div" ).data( "test1", "VALUE-1" );
$( "div" ).data( "test2", "VALUE-2" );
$( "div" ).removeData( "test1" );

// After removal:
// $( "div" ).data( "test1" ) → undefined
// $( "div" ).data( "test2" ) → "VALUE-2"
Try It Yourself

How It Works

Each call to .data(key, value) writes into jQuery’s private store. .removeData("test1") deletes just that entry. The element stays in the DOM; only the cached JavaScript value is gone.

Example 2 — Clear All Cached Data

Call .removeData() with no arguments to wipe every value jQuery holds on the element.

jQuery
$( "#panel" )
  .data( "open", true )
  .data( "index", 3 )
  .data( "label", "Settings" );

$( "#panel" ).removeData();

// All three keys now return undefined (unless data-* attrs exist)
Try It Yourself

How It Works

Use the no-argument form when destroying a plugin instance or resetting a component. It is faster than removing keys one at a time when you no longer need any cached state on the element.

📈 Practical Patterns

Bulk removal, widget teardown, and attribute cleanup.

Example 3 — Remove Multiple Keys (jQuery 1.7+)

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

jQuery
$( "#cart" )
  .data( "items", 4 )
  .data( "total", 59.99 )
  .data( "currency", "USD" )
  .data( "session", "abc123" );

// Array form
$( "#cart" ).removeData( [ "items", "total" ] );

// Or space-separated string
// $( "#cart" ).removeData( "items total" );

// currency and session remain in the cache
Try It Yourself

How It Works

jQuery 1.7 extended .removeData() to accept a list of keys. Each named key is deleted independently; unlisted keys survive. Handy when a plugin stores several related values you want to drop together.

Example 4 — Reset Widget State Before Reinit

Clear stale plugin data before reinitializing a slider on the same element.

jQuery
function destroySlider( $el ) {
  $el.off( ".slider" );
  $el.removeData( "slider" );
}

function initSlider( $el ) {
  destroySlider( $el );
  $el.data( "slider", { min: 0, max: 100, value: 50 } );
  $el.on( "click.slider", function() { /* ... */ } );
}

initSlider( $( "#range" ) );
Try It Yourself

How It Works

Plugin authors typically pair .off(".namespace") with .removeData() during teardown. Without clearing the cache, a second .data("slider") read might return outdated options even after rebinding events.

Example 5 — data-* Attributes Survive removeData

Demonstrate why you need .removeAttr() when HTML attributes must also disappear.

jQuery
// HTML: <div id="box" data-role="dialog"></div>

$( "#box" ).data( "role", "modal" );   // overrides cache
$( "#box" ).removeData( "role" );      // clears cache only

// Re-reads from data-role attribute → "dialog"
$( "#box" ).data( "role" );

// Full cleanup:
$( "#box" ).removeData( "role" ).removeAttr( "data-role" );
Try It Yourself

How It Works

Since jQuery 1.4.3, .data() reads HTML5 data-* attributes into the cache on first access. .removeData() does not touch those attributes. For a permanent delete, chain .removeAttr("data-role") after .removeData("role").

🚀 Common Use Cases

  • Plugin teardown — clear widget state with .removeData("pluginName") when destroying a UI component.
  • Reinitialization — wipe stale options before calling init again on the same element.
  • Memory hygiene — drop large cached objects (maps, arrays) when a panel closes.
  • Selective cleanup — remove temporary keys while keeping long-lived configuration values.
  • Bulk reset — use array or space-separated keys to delete related entries at once (1.7+).
  • Attribute sync — pair with .removeAttr() when HTML data-* markup must match the cache.

🧠 How .removeData() Clears the Cache

1

Match target elements

jQuery collection identifies which DOM nodes to update.

Elements
2

Resolve key(s) to delete

Single name, array, space-separated list, or all keys when no argument is passed.

Keys
3

Delete from internal store

Values removed from jQuery’s private cache — DOM and data-* attrs unchanged.

Cache
4

Return jQuery collection

Same matched set returned for chaining — element remains in the document.

📝 Notes

  • Available since jQuery 1.2.3; bulk key removal added in jQuery 1.7.
  • Only clears jQuery’s internal cache — not HTML data-* attributes.
  • After removal, .data("key") may re-read from a matching data-key attribute.
  • Use .removeAttr("data-key") alongside .removeData("key") for full cleanup.
  • The bulk .data() getter reads data-* attributes once; later .removeData() does not re-trigger attribute parsing.
  • .remove() cleans up data automatically; .detach() preserves it until you clear manually.
  • Returns the jQuery object — safe to chain further DOM or data operations.

Browser Support

.removeData() has been part of jQuery since 1.2.3+. Bulk key removal requires 1.7+. It operates on jQuery's internal data layer, not browser-specific APIs. Works in all browsers supported by your jQuery build — IE6+ through modern evergreen browsers in legacy jQuery versions, and all current browsers in jQuery 3.x and 4.x.

jQuery 1.2.3+

jQuery .removeData()

Universal data-cache cleanup API across jQuery 1.x, 2.x, 3.x, and 4.x. Pair with .data() for storage and .removeAttr() when HTML data-* attributes must also be removed.

100% With jQuery loaded
Google Chrome All versions · Desktop & Mobile
Full support
Mozilla Firefox All versions · Desktop & Mobile
Full support
Apple Safari All versions · macOS & iOS
Full support
Microsoft Edge All versions · Chromium & Legacy
Full support
Internet Explorer IE 6+ · Legacy environments
Full support
Opera All modern versions
Full support
.removeData() Universal

Bottom line: Default choice when clearing jQuery-cached values without removing elements from the DOM.

Conclusion

The jQuery .removeData() method deletes values from the internal data cache on matched elements. Pass a key name to remove one entry, an array or space-separated string for bulk deletion since 1.7, or call with no arguments to clear everything — exactly as the official jQuery demo illustrates.

Remember that HTML data-* attributes are separate from the cache. Use .data() to store values, jQuery.hasData() to check existence without side effects, and .removeAttr() when markup must stay in sync. Next up: hide elements with .hide().

💡 Best Practices

✅ Do

  • Call .removeData() during plugin destroy/teardown routines
  • Pair with .off(".namespace") when unbinding widget events
  • Use bulk removal for related keys added in jQuery 1.7+
  • Chain .removeAttr("data-key") when attributes must also disappear
  • Clear cache before reinitializing components on the same element

❌ Don’t

  • Assume .removeData() removes HTML data-* attributes
  • Expect .removeData() to remove elements from the DOM
  • Confuse it with .remove() — that deletes nodes and cleans up data
  • Store secrets in .data() — values are visible in memory and DevTools
  • Forget detached elements still hold cached data until explicitly cleared

Key Takeaways

Knowledge Unlocked

Six things to remember about .removeData()

The cleanup API for jQuery’s internal element data cache.

6
Core concepts
02

All keys

No args

Clear
[] 03

Bulk

Since 1.7

List
04

vs .data()

Pair API

Store
05

Not attrs

Cache only

Pitfall
06

Chain

jQuery

Return

❓ Frequently Asked Questions

.removeData(name) deletes one value from jQuery's internal data cache on matched elements. .removeData() with no arguments clears all cached values. Returns the jQuery collection for chaining. Available since jQuery 1.2.3.
.data(key, value) stores arbitrary JavaScript data on elements. .removeData(key) deletes that cached value. They are complementary — use .data() to attach plugin state and .removeData() to reset or clean up when a widget is destroyed or reinitialized.
No. .removeData() only clears jQuery's internal cache. HTML data-* attributes on the element remain in the DOM. A later call to .data('key') may re-read the value from the data-key attribute. Use .removeAttr('data-key') alongside .removeData('key') when you need both gone.
Yes, since jQuery 1.7. Pass an array of key names — .removeData(['foo', 'bar']) — or a space-separated string — .removeData('foo bar'). Each listed key is deleted from the internal cache.
.removeData() is the collection method: $('#el').removeData('key'). jQuery.removeData(element, key) is the static utility that requires a native DOM element. Both clear the same internal cache; prefer .removeData() in everyday code. See the Utilities jQuery.removeData() tutorial for the static form.
Call it when resetting widget state, clearing stale plugin options, or before reinitializing a component on the same element. jQuery also cleans up data when elements are removed with .remove(), but detached elements keep their cache until you explicitly clear it or reinsert and overwrite values.
Did you know?

jQuery maintains a private expando-backed cache separate from HTML data-* attributes. When you call .data("role") on an element with data-role="dialog", jQuery copies the attribute into the cache on first read. Calling .removeData("role") clears the cache entry but leaves the attribute in the markup — so the next .data("role") can return "dialog" again. The static jQuery.removeData(element, key) utility clears the same cache if you already hold a raw DOM node.

Next: jQuery .hide() Method

Hide matched elements instantly or with animation.

.hide() tutorial →

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.

6 people found this page helpful