mirror of
https://github.com/jquery/jquery.git
synced 2024-11-23 02:54:22 +00:00
Make sure that wrapInner works on elements that have no contents. Fixes #3552.
This commit is contained in:
parent
3e9ef6f5c0
commit
23d600c66d
@ -77,7 +77,14 @@ jQuery.fn.extend({
|
|||||||
|
|
||||||
wrapInner: function( html ) {
|
wrapInner: function( html ) {
|
||||||
return this.each(function() {
|
return this.each(function() {
|
||||||
jQuery( this ).contents().wrapAll( html );
|
var self = jQuery( this ), contents = self.contents();
|
||||||
|
|
||||||
|
if ( contents.length ) {
|
||||||
|
contents.wrapAll( html );
|
||||||
|
|
||||||
|
} else {
|
||||||
|
self.append( html );
|
||||||
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -145,7 +145,7 @@ test("wrapAll(String|Element)", function() {
|
|||||||
// })
|
// })
|
||||||
|
|
||||||
var testWrapInner = function(val) {
|
var testWrapInner = function(val) {
|
||||||
expect(6);
|
expect(8);
|
||||||
var num = jQuery("#first").children().length;
|
var num = jQuery("#first").children().length;
|
||||||
var result = jQuery('#first').wrapInner('<div class="red"><div id="tmp"></div></div>');
|
var result = jQuery('#first').wrapInner('<div class="red"><div id="tmp"></div></div>');
|
||||||
equals( jQuery("#first").children().length, 1, "Only one child" );
|
equals( jQuery("#first").children().length, 1, "Only one child" );
|
||||||
@ -158,6 +158,11 @@ var testWrapInner = function(val) {
|
|||||||
equals( jQuery("#first").children().length, 1, "Only one child" );
|
equals( jQuery("#first").children().length, 1, "Only one child" );
|
||||||
ok( jQuery("#first").children().is("#empty"), "Verify Right Element" );
|
ok( jQuery("#first").children().is("#empty"), "Verify Right Element" );
|
||||||
equals( jQuery("#first").children().children().length, num, "Verify Elements Intact" );
|
equals( jQuery("#first").children().children().length, num, "Verify Elements Intact" );
|
||||||
|
|
||||||
|
var div = jQuery("<div/>");
|
||||||
|
div.wrapInner("<span></span>");
|
||||||
|
equals(div.children().length, 1, "The contents were wrapped.");
|
||||||
|
equals(div.children()[0].nodeName.toLowerCase(), "span", "A span was inserted.");
|
||||||
}
|
}
|
||||||
|
|
||||||
test("wrapInner(String|Element)", function() {
|
test("wrapInner(String|Element)", function() {
|
||||||
|
Loading…
Reference in New Issue
Block a user