Bug Tracker

Ticket #4383 (closed bug: duplicate)

Opened 6 years ago

Last modified 4 years ago

[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

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

Change History

Changed 6 years ago by Blak

Test case

comment:1 Changed 6 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 4 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 4 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 4 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 4 years ago by snover

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

comment:6 Changed 4 years ago by snover

Duplicate of #5566.

comment:7 Changed 4 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 4 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.