Skip to content

Commit bb5a21d

Browse files
mattlunnkswedberg
authored andcommitted
Remove recommendation that removeData() is the same as data("key", undefined). Closes #542.
1 parent 8592feb commit bb5a21d

4 files changed

Lines changed: 20 additions & 12 deletions

File tree

entries/data.xml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
<argument name="key" type="String">
99
<desc>A string naming the piece of data to set.</desc>
1010
</argument>
11-
<argument name="value" type="Object">
12-
<desc>The new data value; it can be any Javascript type including Array or Object.</desc>
11+
<argument name="value" type="Anything">
12+
<desc>The new data value; this can be any Javascript type except <code>undefined</code>.</desc>
1313
</argument>
1414
</signature>
1515
<signature>
@@ -30,10 +30,11 @@ $( "body" ).data( "foo" ); // 52
3030
$( "body" ).data(); // { foo: 52, bar: { myType: "test", count: 40 }, baz: [ 1, 2, 3 ] }
3131
</code></pre>
3232
<p>In jQuery 1.4.3 setting an element's data object with <code>.data(obj)</code> extends the data previously stored with that element. jQuery itself uses the <code>.data()</code> method to save information under the names 'events' and 'handle', and also reserves any data name starting with an underscore ('_') for internal use.</p>
33-
<p>Prior to jQuery 1.4.3 (starting in jQuery 1.4) the .data() method completely replaced all data, instead of just extending the data object. If you are using third-party plugins it may not be advisable to completely replace the element's data object, since plugins may have also set data.</p>
33+
<p>Prior to jQuery 1.4.3 (starting in jQuery 1.4) the <code>.data()</code> method completely replaced all data, instead of just extending the data object. If you are using third-party plugins it may not be advisable to completely replace the element's data object, since plugins may have also set data.</p>
3434
<p>Due to the way browsers interact with plugins and external code, the <code>.data()</code> method cannot be used on <code>&lt;object&gt;</code> (unless it's a Flash plugin), <code>&lt;applet&gt;</code> or <code>&lt;embed&gt;</code> elements.</p>
3535
</longdesc>
3636
<note id="no-data-on-xml" type="additional"/>
37+
<note id="data-doesnt-accept-undefined" type="additional" data-title=".data" data-parameters="&quot;name&quot;"/>
3738
<example>
3839
<desc>Store then retrieve a value from the div element.</desc>
3940
<code><![CDATA[

entries/jQuery.data.xml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
<argument name="key" type="String">
1212
<desc>A string naming the piece of data to set.</desc>
1313
</argument>
14-
<argument name="value" type="Object">
15-
<desc>The new data value.</desc>
14+
<argument name="value" type="Anything">
15+
<desc>The new data value; this can be any Javascript type except <code>undefined</code>.</desc>
1616
</argument>
1717
</signature>
1818
<desc>Store arbitrary data associated with the specified element. Returns the value that was set.</desc>
@@ -23,8 +23,9 @@
2323
jQuery.data( document.body, "foo", 52 );
2424
jQuery.data( document.body, "bar", "test" );
2525
</code></pre>
26-
<p><em>Note:</em> this method currently does not provide cross-platform support for setting data on XML documents, as Internet Explorer does not allow data to be attached via expando properties.</p>
2726
</longdesc>
27+
<note id="no-data-on-xml" type="additional"/>
28+
<note id="data-doesnt-accept-undefined" type="additional" data-title="jQuery.data" data-parameters="el, &quot;name&quot;"/>
2829
<example>
2930
<desc>Store then retrieve a value from the div element.</desc>
3031
<code><![CDATA[

entries/removeData.xml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,13 @@
1717
</signature>
1818
<desc>Remove a previously-stored piece of data.</desc>
1919
<longdesc>
20-
<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, all values are removed. Removing data from jQuery's internal <code>.data()</code> cache does not affect any HTML5 <code>data-</code> attributes in a document; use <code>.removeAttr()</code> to remove those.</p>
21-
<p>When using <code>.removeData("name")</code>, jQuery will attempt to locate a <code>data-</code> attribute on the element if no property by that name is in the internal data cache. To avoid a re-query of the <code>data-</code> attribute, set the name to a value of either <code>null</code> or <code>undefined</code> (e.g. <code>.data("name", undefined)</code>) rather than using <code>.removeData()</code>.</p>
20+
<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>
21+
<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.
25+
</p>
2226
<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>
23-
<p><strong>As of jQuery 1.4.3</strong>, calling <code>.removeData()</code> will cause the value of the property being removed to revert to the value of the data attribute of the same name in the DOM, rather than being set to <code>undefined</code>.</p>
2427
</longdesc>
2528
<example>
2629
<desc>Set a data store for 2 names then remove one of them.</desc>

notes.xsl

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
22
<xsl:template name="note">
33
<xsl:choose>
4+
<xsl:when test="@id = 'data-doesnt-accept-undefined'">
5+
<code>undefined</code> is not recognised as a data value. Calls such as <code><xsl:value-of select="@data-title" />( <xsl:value-of select="@data-parameters" />, undefined )</code> will return the corresponding data for "name", and is therefore the same as <code><xsl:value-of select="@data-title" />( <xsl:value-of select="@data-parameters" /> )</code>.
6+
</xsl:when>
47
<xsl:when test="@id = 'dimensions-number'">
58
The numbers returned by dimensions-related APIs, including <code><xsl:value-of select="@data-title"/></code>, may be fractional in some cases. Code should not assume it is an integer. Also, dimensions may be incorrect when the page is zoomed by the user; browsers do not expose an API to detect this condition.
69
</xsl:when>
710
<xsl:when test="@id = 'disconnected-manipulation'">
811
Prior to jQuery 1.9, <code><xsl:value-of select="@data-title"/></code> would attempt to add or change nodes in the current jQuery set if the first node in the set was not connected to a document, and in those cases return a new jQuery set rather than the original set. The method might or might not have returned a new result depending on the number or connectedness of its arguments! As of jQuery 1.9, <code>.after()</code>, <code>.before()</code>, and <code>.replaceWith()</code> always return the original unmodified set. Attempting to use these methods on a node without a parent has no effect—that is, neither the set nor the nodes it contains are changed.
912
</xsl:when>
10-
<xsl:when test="@id = 'removes-data'">
11-
The <code><xsl:value-of select="@data-title"/></code> method removes all data and event handlers associated with the removed nodes.
12-
</xsl:when>
1313
<xsl:when test="@id = 'document-order'">
1414
Selected elements are in the order of their appearance in the document.
1515
</xsl:when>
@@ -34,6 +34,9 @@
3434
<xsl:when test="@id = 'propagation-for-live-or-delegate'">
3535
Since the <a href="/live/"><code>.live()</code></a> method handles events once they have propagated to the top of the document, it is not possible to stop propagation of live events. Similarly, events handled by <code><a href="/delegate/">.delegate()</a></code> will propagate to the elements to which they are delegated; event handlers bound on any elements below it in the DOM tree will already have been executed by the time the delegated event handler is called. These handlers, therefore, may prevent the delegated handler from triggering by calling <code><a href="/event.stopPropagation/">event.stopPropagation()</a></code> or returning <code>false</code>.
3636
</xsl:when>
37+
<xsl:when test="@id = 'removes-data'">
38+
The <code><xsl:value-of select="@data-title"/></code> method removes all data and event handlers associated with the removed nodes.
39+
</xsl:when>
3740
<xsl:when test="@id = 'same-origin-policy'">
3841
Due to browser security restrictions, most "Ajax" requests are subject to the <a title="Same Origin Policy on Wikipedia" href="http://en.wikipedia.org/wiki/Same_origin_policy">same origin policy</a>; the request can not successfully retrieve data from a different domain, subdomain, port, or protocol.
3942
</xsl:when>

0 commit comments

Comments
 (0)