forked from jquery/api.jquery.com
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathremoveData.xml
More file actions
60 lines (60 loc) · 2.82 KB
/
removeData.xml
File metadata and controls
60 lines (60 loc) · 2.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?xml version="1.0"?>
<entry type="method" name="removeData" return="jQuery">
<title>.removeData()</title>
<signature>
<added>1.2.3</added>
<argument name="name" type="String" optional="true">
<desc>A string naming the piece of data to delete.</desc>
</argument>
</signature>
<signature>
<added>1.7</added>
<argument name="list" optional="true">
<desc>An array or space-separated string naming the pieces of data to delete.</desc>
<type name="Array"/>
<type name="String"/>
</argument>
</signature>
<desc>Remove a previously-stored piece of data.</desc>
<longdesc>
<p>The <code>.removeData()</code> method allows us to remove values that were previously set using <code>.data()</code>. When called with the name of a key, <code>.removeData()</code> deletes that particular value. When called with no arguments, <code>.removeData()</code> removes all values.</p>
<p>
Note that <code>.removeData()</code> will only remove data from jQuery's internal <code>.data()</code> cache, and any corresponding <code>data-</code> attributes on the element will not be removed. A later call to <code>.data( "key" )</code>
will therefore re-retrieve the value from the <code>data-key</code> attribute. To prevent this, use <code>.removeAttr()</code> alongside <code>.removeData()</code> to remove the <code>data-</code> attribute as well. Prior to jQuery 1.4.3,
as <code>.data()</code> did not use <code>data-</code> attributes, this was not an issue.
</p>
<p>The bulk <code>.data()</code> getter will only fetch <code>data-</code> attributes once, even if <code>.removeData()</code> is called in between <code>.data()</code> calls.</p>
<p><strong>As of jQuery 1.7</strong>, when called with an array of keys or a string of space-separated keys, <code>.removeData()</code> deletes the value of each key in that array or string.</p>
</longdesc>
<example>
<desc>Set a data store for 2 names then remove one of them.</desc>
<code><![CDATA[
$( "span" ).eq( 0 ).text( "" + $( "div" ).data( "test1" ) );
$( "div" ).data( "test1", "VALUE-1" );
$( "div" ).data( "test2", "VALUE-2" );
$( "span" ).eq( 1 ).text( "" + $( "div").data( "test1" ) );
$( "div" ).removeData( "test1" );
$( "span" ).eq( 2 ).text( "" + $( "div" ).data( "test1" ) );
$( "span" ).eq( 3 ).text( "" + $( "div" ).data( "test2" ) );
]]></code>
<css><![CDATA[
div {
margin: 2px;
color: blue;
}
span {
color: red;
}
]]></css>
<html><![CDATA[
<div>value1 before creation: <span></span></div>
<div>value1 after creation: <span></span></div>
<div>value1 after removal: <span></span></div>
<div>value2 after removal: <span></span></div>
]]></html>
</example>
<category slug="data"/>
<category slug="miscellaneous/data-storage"/>
<category slug="version/1.2.3"/>
<category slug="version/1.7"/>
</entry>