Bug Tracker

Opened 7 years ago

Closed 5 years ago

Last modified 5 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 7 years ago.
Test case

Download all attachments as: .zip

Change History (9)

Changed 7 years ago by Blak

Test case

comment:1 Changed 7 years ago by dmethvin

  • Component changed from event to 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 5 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 5 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 5 years ago by snover

  • Milestone changed from 1.4 to 1.4.5
  • Priority changed from low to high
  • Status changed from new to open
  • Version changed from 1.3.2 to 1.4.4rc

comment:5 Changed 5 years ago by snover

  • Resolution set to duplicate
  • Status changed from open to closed

comment:6 Changed 5 years ago by snover

Duplicate of #5566.

comment:7 Changed 5 years ago by john

  • Version changed from 1.4.4rc to 1.5

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

comment:8 Changed 5 years ago by john

  • Milestone changed from 1.4.5 to 1.5

There was no 1.4.5 release, was actually 1.5.

Note: See TracTickets for help on using tickets.