From: John Resig Date: Tue, 8 Dec 2009 19:21:24 +0000 (-0800) Subject: Make sure that events are cloned for wrap, fixes #2977. X-Git-Url: http://git.asbjorn.biz/?p=jquery.git;a=commitdiff_plain;h=f5b649fafbd85a1973a9c46ca6bf163d9de857a7 Make sure that events are cloned for wrap, fixes #2977. --- diff --git a/src/manipulation.js b/src/manipulation.js index 1fe82fa..0c2753e 100644 --- a/src/manipulation.js +++ b/src/manipulation.js @@ -48,7 +48,7 @@ jQuery.fn.extend({ if ( this[0] ) { // The elements to wrap the target around - var wrap = jQuery( html, this[0].ownerDocument ).eq(0).clone(); + var wrap = jQuery( html, this[0].ownerDocument ).eq(0).clone(true); if ( this[0].parentNode ) { wrap.insertBefore( this[0] ); diff --git a/test/unit/manipulation.js b/test/unit/manipulation.js index 44fafa9..4631ead 100644 --- a/test/unit/manipulation.js +++ b/test/unit/manipulation.js @@ -13,7 +13,7 @@ test("text()", function() { }); var testWrap = function(val) { - expect(15); + expect(18); var defaultText = 'Try them out:' var result = jQuery('#first').wrap(val( '
' )).text(); equals( defaultText, result, 'Check for wrapping of on-the-fly html' ); @@ -54,6 +54,20 @@ var testWrap = function(val) { equals( j[0].parentNode.parentNode.childNodes.length, 1, "There should only be one element wrapping." ); equals( j.length, 1, "There should only be one element (no cloning)." ); equals( j[0].parentNode.nodeName.toUpperCase(), "P", "The span should be in the paragraph." ); + + // Wrap an element with a jQuery set + j = jQuery("").wrap(jQuery("
")); + equals( j[0].parentNode.nodeName.toLowerCase(), "div", "Wrapping works." ); + + // Wrap an element with a jQuery set and event + result = jQuery("
").click(function(){ + ok(true, "Event triggered."); + }); + + j = jQuery("").wrap(result); + equals( j[0].parentNode.nodeName.toLowerCase(), "div", "Wrapping works." ); + + j.parent().trigger("click"); } test("wrap(String|Element)", function() {