1 line
2.7 KiB
JSON
1 line
2.7 KiB
JSON
{"name":"removeData","type":"method","title":".removeData()","deprecated":null,"removed":null,"desc":"Remove a previously-stored piece of data.","categories":["data","miscellaneous/data-storage","version/1.2.3","version/1.7"],"entries":[{"return":"jQuery","signatures":[{"added":"1.2.3","argument":{"desc":"A string naming the piece of data to delete.","name":"name","type":"String","optional":"true"}},{"added":"1.7","argument":{"desc":"An array or space-separated string naming the pieces of data to delete.","type":[{"name":"Array"},{"name":"String"}],"name":"list","optional":"true"}}],"examples":{"desc":"Set a data store for 2 names then remove one of them.","code":"\n$( \"span:eq(0)\" ).text( \"\" + $( \"div\" ).data( \"test1\" ) );\n$( \"div\" ).data( \"test1\", \"VALUE-1\" );\n$( \"div\" ).data( \"test2\", \"VALUE-2\" );\n$( \"span:eq(1)\" ).text( \"\" + $( \"div\").data( \"test1\" ) );\n$( \"div\" ).removeData( \"test1\" );\n$( \"span:eq(2)\" ).text( \"\" + $( \"div\" ).data( \"test1\" ) );\n$( \"span:eq(3)\" ).text( \"\" + $( \"div\" ).data( \"test2\" ) );\n","css":"\n div {\n margin: 2px;\n color: blue;\n }\n span {\n color: red;\n }\n","html":"\n<div>value1 before creation: <span></span></div>\n<div>value1 after creation: <span></span></div>\n<div>value1 after removal: <span></span></div>\n<div>value2 after removal: <span></span></div>\n"},"longdesc":"\n <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 effect any HTML5 <code>data-</code> attributes in a document; use <code>.removeAttr()</code> to remove those.</p>\n <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>\n <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>\n <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>\n "}]} |