Bug Tracker

Opened 14 years ago

Closed 12 years ago

Last modified 12 years ago

#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)

test.htm (2.4 KB) - added by Blak 14 years ago.
Test case

Download all attachments as: .zip

Change History (9)

Changed 14 years ago by Blak

Attachment: test.htm added

Test case

comment:1 Changed 14 years ago by dmethvin

Component: eventcore
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 Rick Waldron

Owner: changed from john to Blak
Priority: minorlow
Status: newpending

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 Blak

Status: pendingnew

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 snover

Milestone: 1.41.4.5
Priority: lowhigh
Status: newopen
Version: 1.3.21.4.4rc

comment:5 Changed 12 years ago by snover

Resolution: duplicate
Status: openclosed

comment:6 Changed 12 years ago by snover

Duplicate of #5566.

comment:7 Changed 12 years ago by john

Version: 1.4.4rc1.5

There wasn't a 1.4.5 release, was actually 1.5.

comment:8 Changed 12 years ago by john

Milestone: 1.4.51.5

There was no 1.4.5 release, was actually 1.5.

Note: See TracTickets for help on using tickets.