jQuery .removeData() Method

Beginner
⏱️ 9 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Data utility

What You’ll Learn

jQuery.removeData(element [, name]) deletes values previously stored with jQuery.data(). This tutorial covers removing one key vs clearing all data, the official demo, how it differs from .removeData(), data-* pitfalls, five examples, and try-it labs.

01

Remove key

By name

02

Clear all

No name

03

Element

Raw DOM node

04

vs .removeData()

Prefer instance

05

Not attr

Cache only

06

Since 1.2.3

Low-level

Introduction

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

After you attach values with jQuery.data() or .data(), you often need to clean them up — widget destroy, reset, or re-init. Since jQuery 1.2.3, jQuery.removeData(element [, name]) is the low-level way to delete those cached entries for a single DOM node.

Official docs note this is low-level: day to day, prefer $(element).removeData(). Learn the static form so you can read utility demos and work when you already hold a raw element. See the Utilities hub and jQuery.data().

Understanding the jQuery.removeData() Method

Pass a DOM element first. Optionally pass a string name for the key to delete. Omit name to wipe the whole store for that element.

Only the internal jQuery cache is affected. HTML data-* attributes are left alone unless you also call .removeAttr().

💡
Beginner Tip

Think of jQuery.removeData(el, "foo") as erasing one sticky note on the element. Prefer $(el).removeData("foo") when you are already in jQuery chaining land.

📝 Syntax

Signature (jQuery 1.2.3+):

jQuery
jQuery.removeData( element [, name ] )

Parameters

  • element (Element) — DOM node whose data should be cleared.
  • name (String, optional) — key to remove. Omit to remove all stored values for the element.

Return value

  • undefined — not chainable like .removeData().

Official pattern

jQuery
var div = $( "div" )[ 0 ];
jQuery.data( div, "test1", "VALUE-1" );
jQuery.data( div, "test2", "VALUE-2" );
jQuery.removeData( div, "test1" );
// test1 gone; test2 still "VALUE-2"

⚡ Quick Reference

GoalCode
Remove one keyjQuery.removeData( el, "test1" )
Clear all keysjQuery.removeData( el )
Preferred instance API$( el ).removeData( "test1" )
Also drop attribute$( el ).removeAttr( "data-test1" )
Input
Element

Raw DOM node required

Optional
name

Key to delete

Returns
undefined

No chaining from static call

Prefer
.removeData()

Instance method for apps

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

jQuery.removeData(el)$(el).removeData().removeAttr("data-…")
TargetjQuery cachejQuery cacheHTML attribute
InputDOM elementjQuery collectionjQuery collection
Best forLow-level / demosEveryday cleanupMarkup cleanup

Examples Gallery

Examples follow the official jQuery API demo and practical cleanup patterns.

📚 Getting Started

Remove one key after storing two — the official pattern.

Example 1 — Official Demo: Remove One of Two Keys

Set test1 and test2, then remove only test1.

jQuery
var div = $( "div" )[ 0 ];
$( "span" ).eq( 0 ).text( "" + $( "div" ).data( "test1" ) );
jQuery.data( div, "test1", "VALUE-1" );
jQuery.data( div, "test2", "VALUE-2" );
$( "span" ).eq( 1 ).text( "" + jQuery.data( div, "test1" ) );
jQuery.removeData( div, "test1" );
$( "span" ).eq( 2 ).text( "" + jQuery.data( div, "test1" ) );
$( "span" ).eq( 3 ).text( "" + jQuery.data( div, "test2" ) );
Try It Yourself

How It Works

Removing test1 leaves test2 intact. Reading a missing key returns undefined.

Example 2 — Clear All Data (No Name)

Call jQuery.removeData(el) with only the element.

jQuery
var el = document.getElementById( "box" );
jQuery.data( el, "a", 1 );
jQuery.data( el, "b", 2 );
jQuery.removeData( el );
console.log( jQuery.data( el ) ); // {} (or empty store)
Try It Yourself

How It Works

Useful before re-initializing a widget on the same node when you want a clean slate.

📈 Practical Patterns

Attributes, instance API, and plugin teardown.

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)
jQuery.removeData( el, "score" );
$( "#x" ).attr( "data-score" );      // still "10"
$( "#x" ).data( "score" );           // may become 10 again from attr
Try It Yourself

How It Works

Pair removeData with removeAttr when both sources must go.

Example 4 — jQuery.removeData vs .removeData()

Equivalent cleanup on the same cache.

jQuery
var el = $( "#box" )[ 0 ];
jQuery.data( el, "x", 1 );

// Static utility (this tutorial)
jQuery.removeData( el, "x" );

// Preferred instance method
$( "#box" ).data( "x", 1 ).removeData( "x" );
Try It Yourself

How It Works

Choose based on whether you have a jQuery object or a raw node already in hand.

Example 5 — Plugin Destroy Cleanup

Clear options stored on the host element when destroying a tiny plugin.

jQuery
$.fn.counter = function( opts ) {
  return this.each(function() {
    jQuery.data( this, "counter", opts || { n: 0 } );
  });
};
$.fn.counterDestroy = function() {
  return this.each(function() {
    jQuery.removeData( this, "counter" );
  });
};

$( "#box" ).counter( { n: 5 } );
$( "#box" ).counterDestroy();
Try It Yourself

How It Works

Inside .each, this is already a DOM element — a natural fit for the static API.

🚀 Common Use Cases

  • Plugin destroy — drop options and timers stored on the host node.
  • Reset before re-init — clear stale keys so new options win.
  • Official-style samples — pair with jQuery.data on div[0].
  • Raw DOM helpers — when you already unwrapped a collection.
  • Partial cleanup — remove one key and keep others.
  • Learning path — bridge to .removeData().

🧠 How jQuery.removeData Fits

1

Data was stored

jQuery.data or .data() wrote keys into the cache.

Store
2

Call removeData

Pass the element and optional key name.

Delete
3

Cache updates

That key (or all keys) disappears from the store.

Cache
4

Attributes unchanged

Remove data-* separately if markup must change.

📝 Notes

  • Added in jQuery 1.2.3; still in modern jQuery 3.x.
  • Official guidance: prefer .removeData().
  • First argument must be a DOM element.
  • Does not remove HTML data-* attributes.
  • Returns undefined (not a jQuery object).
  • Instance .removeData() also supports arrays / space-separated names (1.7+) — richer than this static signature.
  • Related: jQuery.data(), .data(), jQuery.hasData().

Browser Support

jQuery.removeData() has been part of jQuery since 1.2.3+. It works in every browser supported by your jQuery build — including modern evergreen browsers with jQuery 3.x.

jQuery 1.2.3+

jQuery.removeData()

Stable low-level data cleanup utility. Prefer .removeData() on collections for everyday code.

100% With jQuery 1.2.3+
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
jQuery.removeData 1.2.3+

Bottom line: Use to clear jQuery’s cache on a raw element; use .removeData() when chaining.

Conclusion

jQuery.removeData() deletes cached values for a DOM element — one key or all of them. It is the low-level twin of .removeData(). Prefer the instance method in app code; use the static form with raw nodes and utility demos.

Next up: jQuery.queue() for element function queues.

💡 Best Practices

✅ Do

  • Pass a real DOM element to jQuery.removeData
  • Remove named keys on destroy when possible
  • Also removeAttr when attributes must go
  • Prefer .removeData() in new UI code
  • Pair with jQuery.data in low-level helpers

❌ Don’t

  • Pass a jQuery object as element
  • Expect attributes to disappear automatically
  • Assume chaining works on the return value
  • Confuse this with deleting DOM nodes (.remove())
  • Forget that .data() may re-read data-* later

Key Takeaways

Knowledge Unlocked

Five things to remember about jQuery.removeData

The low-level cache cleanup utility.

5
Core concepts
DOM 02

Needs

Element

Arg
* 03

Optional

name

Key
04

Not

attr

Markup
05

Prefer

.removeData()

Instance

❓ 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. Prefer $(element).removeData() for everyday code.
Same cache, different call shape. jQuery.removeData(el, key) takes a raw DOM element. .removeData() is called on a jQuery collection and is chainable. Official docs recommend .removeData(); this static method is the low-level twin used in utilities and older samples.
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 you 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.
Did you know?

The official jQuery.removeData demo uses both $("div").data() and jQuery.data(div, …) in the same snippet — a reminder that the collection and static APIs share one cache, even when demos mix call styles.

Next: jQuery.queue() Method

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

jQuery.queue() 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.

7 people found this page helpful