diff --git a/src/manipulation.js b/src/manipulation.js
index b5ace4d73..55017c196 100644
--- a/src/manipulation.js
+++ b/src/manipulation.js
@@ -24,7 +24,7 @@ jQuery.fn.extend({
if ( this[0] ) {
// The elements to wrap the target around
- var wrap = jQuery( html, this[0].ownerDocument ).clone();
+ var wrap = jQuery( html, this[0].ownerDocument ).eq(0).clone();
if ( this[0].parentNode )
wrap.insertBefore( this[0] );
diff --git a/test/unit/manipulation.js b/test/unit/manipulation.js
index ca185a47e..88e7d7107 100644
--- a/test/unit/manipulation.js
+++ b/test/unit/manipulation.js
@@ -10,7 +10,7 @@ test("text()", function() {
});
var testWrap = function(val) {
- expect(12);
+ expect(15);
var defaultText = 'Try them out:'
var result = jQuery('#first').wrap(val( '
' )).text();
equals( defaultText, result, 'Check for wrapping of on-the-fly html' );
@@ -45,6 +45,12 @@ var testWrap = function(val) {
j = jQuery("").wrap("test
");
equals( j[0].previousSibling.nodeType, 3, "Make sure the previous node is a text element" );
equals( j[0].parentNode.nodeName.toUpperCase(), "DIV", "And that we're in the div element." );
+
+ // Try to wrap an element with multiple elements (should fail)
+ j = jQuery("
").children().wrap("");
+ 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." );
}
test("wrap(String|Element)", function() {