Side navigation
#4346 closed bug (worksforme)
Opened March 13, 2009 10:17AM UTC
Closed December 09, 2009 09:33PM UTC
Data missing after adding to two elements.
Reported by: | kondziu | Owned by: | |
---|---|---|---|
Priority: | major | Milestone: | 1.4 |
Component: | data | Version: | 1.4a1 |
Keywords: | data, missing, multi element add | Cc: | |
Blocked by: | Blocking: |
Description
jQ 1.2.6 and 1.3.2
jQuery('body').append(jQuery('<ul id="list1">'));
jQuery('body').append(jQuery('<ul id="list2">'));
creating element with data
var li = jQuery('<li>').text('x').data('foo', 'bar');
console.info(jQuery.data(li[0])); -> 2
console.info(jQuery.data(li[0], 'foo')); -> bar
after adding to two elements ...
jQuery('#list1, #list2').prepend(li);
console.info(jQuery.data(jQuery('#list1 li')[0])); -> 7 (OK)
console.info(jQuery.data(, 'foo')); -> undefined
console.info(jQuery.data(jQuery('#list2 li')[0])); -> 8 (OK)
console.info(jQuery.data(jQuery('#list2 li')[0], 'foo')); -> undefined
data is missing
Attachments (0)
Change History (5)
Changed March 13, 2009 10:21AM UTC by comment:1
Changed March 14, 2009 12:55AM UTC by comment:2
jQuery('#list1, #list2').prepend(li);
Since there are two elements in the jQuery object, the prepend is cloning the original li and appending the clone to the second element. The clone does not have the data.
I think the logic behind this is that copying all the
.datato all elements would be expensive (and remember that
.dataincludes all events as well). You still have the option to explicitly copy the data, or better still attach events and data after the implicit cloning occurs.
The docs aren't clear on this, so I'd suggest clearly documenting the behavior to resolve the ticket.
Changed June 02, 2009 10:16AM UTC by comment:3
Changed August 09, 2009 01:38AM UTC by comment:4
component: | unfilled → data |
---|---|
milestone: | 1.3.2 → 1.3.3 |
Changed December 09, 2009 09:33PM UTC by comment:5
resolution: | → worksforme |
---|---|
status: | new → closed |
version: | 1.2.6 → 1.4a1 |
In this case you should clone the elements so that you explicitly carry over the data from the old ones (considering that what you describe doesn't carry over events either, this seems like a fair request).
Since #4191 is already fixed this should be as simple as doing .clone(true).