Side navigation
#11438 closed bug (invalid)
Opened March 05, 2012 04:32PM UTC
Closed March 05, 2012 05:01PM UTC
Last modified August 16, 2012 01:52PM UTC
Non-persistence of events when reappending dom nodes to their original parent
Reported by: | wheresrhys | Owned by: | |
---|---|---|---|
Priority: | undecided | Milestone: | None |
Component: | unfiled | Version: | 1.7.1 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
I'm not sure if this is a bug or intended behaviour, but when using .html() to reappend elements elements to their original parent then any jQuery events for these elements are lost. This desn't happen when appending the elements to a different node using html() or when using append() to append the elements to the existing parent.
http://jsfiddle.net/wheresrhys/tPcEE/
Obviously, appending an element to its existing parent using html() is not something you'd normally do on purpose, but could crop up when iterating over a large number of nodes which may/may not have been moved by other processes in your app.
As html() is only documented as accepting strings I reckon this is probably a won't fix, but thought I'd bring it up just in case.
Attachments (0)
Change History (4)
Changed March 05, 2012 05:01PM UTC by comment:1
keywords: | → needsdocs |
---|---|
resolution: | → invalid |
status: | new → closed |
Changed March 06, 2012 10:07AM UTC by comment:2
I actually think it's a problem in general with jQuery/jQuery docs that jQuery works for a lot more cases than it officially supports. As you said above, there is in fact some specific code within .html(x) for when x is not a string - if jQuery truly didn't support this then it should just throw an error/do nothing here. I'm not arguing for this feature to be removed/deprecated as it's generally useful, but this kind of grey area exists all over jQuery - there's been a few times when I've reported/thought about reporting a "bug" only to find that it's an instance of jQuery not supporting what it, surprisingly, doesn't officially support. So it's not too outlandish a suggestion to document in greater detail the limitations of jQuery's functionality when it so often steps beyond what it says it supports.
Changed March 06, 2012 01:42PM UTC by comment:3
People misuse the undocumented edges of every interface we offer. We're not going to add more code to break the edges, that is pretty user-hostile.
Changed August 16, 2012 01:52PM UTC by comment:4
keywords: | needsdocs |
---|
Internally,
.html(x)
calls.empty().append(x)
for x that isn't a string. So knowing that it should be clear that.empty()
is removing the events. But I agree that it is not a good idea to pass anything but a string to.html()
since that is what it is documented to accept. At most we might want to add a note to this effect, but I am not even sure about that. ("Warning: only pass a string to.html()
yeah I'm talking to you, like it tells you to do.")