Skip to content

Commit

Permalink
Fixed #2027 - make sure that cloned elements (within appendTo, etc.) …
Browse files Browse the repository at this point in the history
…have their events cloned by default.
  • Loading branch information
jeresig committed Dec 20, 2007
1 parent b740fe5 commit 3261544
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/core.js
Expand Up @@ -498,7 +498,7 @@ jQuery.fn = jQuery.prototype = {

jQuery.each(elems, function(){
var elem = clone ?
this.cloneNode( true ) :
jQuery( this ).clone( true )[0] :
this;

// execute all scripts after the elements have been injected
Expand Down
7 changes: 6 additions & 1 deletion test/unit/event.js
@@ -1,7 +1,7 @@
module("event");

test("bind()", function() {
expect(18);
expect(19);

var handler = function(event) {
ok( event.data, "bind() with data, check passed data exists" );
Expand Down Expand Up @@ -85,6 +85,11 @@ test("bind()", function() {
$("#nonnodes").contents().bind("tester", function () {
equals(this.nodeType, 1, "Check node,textnode,comment bind just does real nodes" );
}).trigger("tester");

// Make sure events stick with appendTo'd elements (which are cloned) #2027
$("<a href='#fail' class='test'>test</a>").click(function(){ return false; }).appendTo("p");
ok( $("a.test:first").triggerHandler("click") === false, "Handler is bound to appendTo'd elements" );
reset();
});

test("click()", function() {
Expand Down

0 comments on commit 3261544

Please sign in to comment.