Bug Tracker

Opened 13 years ago

Closed 12 years ago

Last modified 11 years ago

#6439 closed bug (fixed)

append() removes all data when used on multiple elements

Reported by: thesaint Owned by:
Priority: undecided Milestone:
Component: manipulation Version: 1.4.2
Keywords: append data events Cc:
Blocked by: Blocking:


When a fragment with data is created and it is appended with "append()" to multiple elements, the fragment is inserted without the data (thus, event handlers are also wiped). "appendTo()" doesn't show this behavior. Also, when "append()" is used for a single element, the data isn't lost. See the attached file.

Attachments (1)

jqerror.html (560 bytes) - added by thesaint 13 years ago.

Download all attachments as: .zip

Change History (8)

Changed 13 years ago by thesaint

Attachment: jqerror.html added

comment:1 Changed 13 years ago by dmethvin

I can see how this would happen, since the elements have to be cloned to append to multiple locations. Were you expecting to see the data cloned into new separate objects that would be associated with the elements? Or would you expect the elements to all share the original common data object?

comment:2 Changed 13 years ago by thesaint

Hmm, firstly I expected the data to be there at all :-)

Here are my thoughts: The most important use case for data are bound events. From a memory perspective it seems better to me when the event handler is shared across all elements. And at the moment I can't think of a scenario where cloned event handlers are more useful than shared event handlers. What happens when you call .bind() on multiple elements, is the handler cloned? What's the behavior of appendTo()? I think consistency is a good thing here.

comment:3 Changed 12 years ago by snover

Milestone: 1.4.3

Resetting milestone to future.

comment:4 Changed 12 years ago by dmethvin

Priority: undecided
Status: newopen

comment:5 Changed 12 years ago by dmethvin

I guess this is a case of two cases that look similar justifiably doing very different things.

For the case $("#elem1").appendTo("#elem2") I think we *want* to have everything preserved; we are just moving #elem1 to another point in the DOM tree. For example you might move an option element between two select boxes.

For $("#elem1").appendTo(".lotsaElems") I am less confident. (For one, if it were truly an element with an id you've created an invalid document but let's ignore that for a second.) I can see a strong case for cloning the attached data (and thus the events as well).

comment:6 Changed 12 years ago by danheberden

Seems to be working properly - http://jsfiddle.net/danheberden/EKB4x/

comment:7 Changed 12 years ago by danheberden

Resolution: fixed
Status: openclosed
Note: See TracTickets for help on using tickets.