]> source.dussan.org Git - jquery.git/commitdiff
Fixed #2027 - make sure that cloned elements (within appendTo, etc.) have their event...
authorJohn Resig <jeresig@gmail.com>
Thu, 20 Dec 2007 13:36:56 +0000 (13:36 +0000)
committerJohn Resig <jeresig@gmail.com>
Thu, 20 Dec 2007 13:36:56 +0000 (13:36 +0000)
src/core.js
test/unit/event.js

index 33e109b92e598df0ce49c15a484a4401e2921a24..c2f94d2b77f5fc54dfaae20e06c88e5ee7cf7b07 100644 (file)
@@ -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
index 248094a9666ca3f08ac70b0b96316172c42fbdaf..43a4542f0c427627bc88500cfadc32a8fbd22c5e 100644 (file)
@@ -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" );
@@ -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() {