Commit 991dafae authored by John Resig's avatar John Resig

Fixed wrapping of elements that hold text nodes. Thanks to David Flanagan for...

Fixed wrapping of elements that hold text nodes. Thanks to David Flanagan for the patch. Fixes #4902.
parent ad5ba1a7
...@@ -32,7 +32,7 @@ jQuery.fn.extend({ ...@@ -32,7 +32,7 @@ jQuery.fn.extend({
wrap.map(function(){ wrap.map(function(){
var elem = this; var elem = this;
while ( elem.firstChild ) while ( elem.firstChild && elem.firstChild.nodeType === 1 )
elem = elem.firstChild; elem = elem.firstChild;
return elem; return elem;
......
...@@ -10,7 +10,7 @@ test("text()", function() { ...@@ -10,7 +10,7 @@ test("text()", function() {
}); });
var testWrap = function(val) { var testWrap = function(val) {
expect(10); expect(12);
var defaultText = 'Try them out:' var defaultText = 'Try them out:'
var result = jQuery('#first').wrap(val( '<div class="red"><span></span></div>' )).text(); var result = jQuery('#first').wrap(val( '<div class="red"><span></span></div>' )).text();
equals( defaultText, result, 'Check for wrapping of on-the-fly html' ); equals( defaultText, result, 'Check for wrapping of on-the-fly html' );
...@@ -40,6 +40,11 @@ var testWrap = function(val) { ...@@ -40,6 +40,11 @@ var testWrap = function(val) {
j = jQuery("<label/>").wrap(val( "<li/>" )); j = jQuery("<label/>").wrap(val( "<li/>" ));
equals( j[0].nodeName.toUpperCase(), "LABEL", "Element is a label" ); equals( j[0].nodeName.toUpperCase(), "LABEL", "Element is a label" );
equals( j[0].parentNode.nodeName.toUpperCase(), "LI", "Element has been wrapped" ); equals( j[0].parentNode.nodeName.toUpperCase(), "LI", "Element has been wrapped" );
// Wrap an element containing a text node
j = jQuery("<span/>").wrap("<div>test</div>");
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." );
} }
test("wrap(String|Element)", function() { test("wrap(String|Element)", function() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment