Ticket #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: | |
| Blocking: | Blocked by: |
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
Change History
comment:1 Changed 4 years ago by dmethvin
- Owner changed from brandon to john
- Component changed from event to core
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 3 years ago by rwaldron
- Owner changed from john to Blak
- Priority changed from minor to low
- Status changed from new to 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 3 years ago by Blak
- Status changed from pending to 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 3 years ago by snover
- Priority changed from low to high
- Status changed from new to open
- Version changed from 1.3.2 to 1.4.4rc
- Milestone changed from 1.4 to 1.4.5
comment:5 Changed 3 years ago by snover
- Status changed from open to closed
- Resolution set to duplicate
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.


Test case