From: jeresig Date: Tue, 1 Feb 2011 13:57:18 +0000 (-0500) Subject: The default for .clone() is to not clone any events. Fixes #8123. X-Git-Url: http://git.asbjorn.biz/?p=jquery.git;a=commitdiff_plain;h=375b78783825b9adab7a01541faf99f98ef7ecbd The default for .clone() is to not clone any events. Fixes #8123. --- diff --git a/src/manipulation.js b/src/manipulation.js index 442a14d..1ef19f8 100644 --- a/src/manipulation.js +++ b/src/manipulation.js @@ -184,7 +184,7 @@ jQuery.fn.extend({ }, clone: function( dataAndEvents, deepDataAndEvents ) { - dataAndEvents = dataAndEvents == null ? true : dataAndEvents; + dataAndEvents = dataAndEvents == null ? false : dataAndEvents; deepDataAndEvents = deepDataAndEvents == null ? dataAndEvents : deepDataAndEvents; return this.map( function () { diff --git a/test/unit/manipulation.js b/test/unit/manipulation.js index f0e2eae..e071086 100644 --- a/test/unit/manipulation.js +++ b/test/unit/manipulation.js @@ -953,6 +953,17 @@ test("clone()", function() { div.remove(); clone.remove(); + var divEvt = jQuery("
").click(function(){ + ok( false, "Bound event still exists after .clone()." ); + }), + cloneEvt = divEvt.clone(); + + // Make sure that doing .clone() doesn't clone events + cloneEvt.trigger("click"); + + cloneEvt.remove(); + divEvt.remove(); + // this is technically an invalid object, but because of the special // classid instantiation it is the only kind that IE has trouble with, // so let's test with it too.