#4383 closed bug (duplicate)
[regression] Append with multiple elements doesn't bind events
Reported by: | Blak | Owned by: | Blak |
---|---|---|---|
Priority: | high | Milestone: | 1.5 |
Component: | core | Version: | 1.5 |
Keywords: | regression append event | Cc: | |
Blocked by: | Blocking: |
Description
When attempting to use append to add a button (complete with click event handler) to multiple elements, the button appears however the click events are not bound.
This only appears to effect browsers that use addEventListener, in IE it works as expected.
The following does not bind an event to the buttons
var button = $("<input type='button' value='Click Me!' />").click(function(){ alert("hello"); }); //there are 2 divs inside #append $("#append div").append(button);
However using
button.appendTo("#appendto div");
works as expected in all browsers tested (FF3, Opera9, Safari3 (Win), IE6, IE7).
Both methods work when using jQuery 1.2.6 or if you're appending to a single element.
Attachments (1)
Change History (9)
Changed 14 years ago by
comment:1 Changed 14 years ago by
Component: | event → core |
---|---|
Owner: | changed from brandon to john |
The problem seems to be that .append()
goes through the internal domManip
function; that uses the DOM cloneNode method which doesn't copy events. The .appendTo()
method uses jQuery's .clone()
method, which does copy events.
Although the end result is that events are lost, this is more of a core DOM manipulation issue so I'll reassign it there.
comment:2 Changed 12 years ago by
Owner: | changed from john to Blak |
---|---|
Priority: | minor → low |
Status: | new → pending |
Please provide a reduced jsFiddle test case, thanks!
Additionally, test against the jQuery 0 GIT version to ensure the issue still exists.
comment:3 Changed 12 years ago by
Status: | pending → new |
---|
Tested against jQuery 0 GIT and the problems still exists.
jsFiddle test case can be found at: http://jsfiddle.net/PC5vu/2/
comment:4 Changed 12 years ago by
Milestone: | 1.4 → 1.4.5 |
---|---|
Priority: | low → high |
Status: | new → open |
Version: | 1.3.2 → 1.4.4rc |
comment:5 Changed 12 years ago by
Resolution: | → duplicate |
---|---|
Status: | open → closed |
comment:7 Changed 12 years ago by
Version: | 1.4.4rc → 1.5 |
---|
There wasn't a 1.4.5 release, was actually 1.5.
comment:8 Changed 12 years ago by
Milestone: | 1.4.5 → 1.5 |
---|
There was no 1.4.5 release, was actually 1.5.
Test case