From 991dafae16e44512c5107b90bc8ce9675d8f5c12 Mon Sep 17 00:00:00 2001 From: John Resig Date: Tue, 14 Jul 2009 23:28:07 +0000 Subject: [PATCH] Fixed wrapping of elements that hold text nodes. Thanks to David Flanagan for the patch. Fixes #4902. --- src/manipulation.js | 2 +- test/unit/manipulation.js | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/manipulation.js b/src/manipulation.js index 57b607a..b5ace4d 100644 --- a/src/manipulation.js +++ b/src/manipulation.js @@ -32,7 +32,7 @@ jQuery.fn.extend({ wrap.map(function(){ var elem = this; - while ( elem.firstChild ) + while ( elem.firstChild && elem.firstChild.nodeType === 1 ) elem = elem.firstChild; return elem; diff --git a/test/unit/manipulation.js b/test/unit/manipulation.js index d8dbca9..ca185a4 100644 --- a/test/unit/manipulation.js +++ b/test/unit/manipulation.js @@ -10,7 +10,7 @@ test("text()", function() { }); var testWrap = function(val) { - expect(10); + expect(12); var defaultText = 'Try them out:' var result = jQuery('#first').wrap(val( '
' )).text(); equals( defaultText, result, 'Check for wrapping of on-the-fly html' ); @@ -40,6 +40,11 @@ var testWrap = function(val) { j = jQuery("