Created
December 1, 2009 19:34
-
-
Save rondevera/246561 to your computer and use it in GitHub Desktop.
jQuery $().data gotcha: A collection can be removed from and re-added to the DOM, but its data disappears.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Using jQuery 1.3.2: | |
// Setup: | |
var $foo = $('<div id="foo"></div>').appendTo('body'); | |
$foo; // => [div#foo] | |
$foo.data('bar', 123); | |
$foo.data('bar'); // => 123 | |
// Teardown: | |
$foo.remove(); // => [div#foo] | |
$foo.data('bar'); // => undefined | |
// Re-setup: | |
$foo.appendTo('body'); // => [div#foo] | |
$foo.data('bar'); // undefined |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment