← Back to Index

.removeData()

Remove a previously-stored piece of data.

Examples

1. Remove specific key

$('div').data('id', 123);
$('div').removeData('id');

Result

// $('div').data('id') returns undefined

2. Remove all data

$('div').removeData();

Result

// All internal cached data for the element is cleared.

3. Remove multiple keys

$('div').data({ id: 1, role: 'user' });
$('div').removeData('id role'); // or ['id', 'role']

Result

// Both 'id' and 'role' are removed from internal cache.
// $('div').data() would return {}.

Parameters

Parameter Type Description
name string | array Optional. A space-separated string or an array of keys to delete. If omitted, all data for the element is removed.

Returns: The original SR object for chaining.