Skip to content

Commit 3f27654

Browse files
authored
removeData: Note .removeData() doesn't cause .data() to re-fetch data-attrs
Closes gh-1296 Ref jquery/jquery#5751
1 parent f573ebf commit 3f27654

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

entries/removeData.xml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@
1919
<longdesc>
2020
<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>
2121
<p>
22-
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()</code>
23-
will therefore re-retrieve the value from the <code>data-</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,
24-
as <code>data()</code> did not use <code>data-</code> attributes, this was not an issue.
22+
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>
23+
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,
24+
as <code>.data()</code> did not use <code>data-</code> attributes, this was not an issue.
2525
</p>
26+
<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>
2627
<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>
2728
</longdesc>
2829
<example>

0 commit comments

Comments
 (0)