File tree Expand file tree Collapse file tree 2 files changed +14
-2
lines changed
Expand file tree Collapse file tree 2 files changed +14
-2
lines changed Original file line number Diff line number Diff line change @@ -77,7 +77,14 @@ jQuery.fn.extend({
7777
7878 wrapInner : function ( html ) {
7979 return this . each ( function ( ) {
80- jQuery ( this ) . contents ( ) . wrapAll ( html ) ;
80+ var self = jQuery ( this ) , contents = self . contents ( ) ;
81+
82+ if ( contents . length ) {
83+ contents . wrapAll ( html ) ;
84+
85+ } else {
86+ self . append ( html ) ;
87+ }
8188 } ) ;
8289 } ,
8390
Original file line number Diff line number Diff line change @@ -145,7 +145,7 @@ test("wrapAll(String|Element)", function() {
145145// })
146146
147147var testWrapInner = function ( val ) {
148- expect ( 6 ) ;
148+ expect ( 8 ) ;
149149 var num = jQuery ( "#first" ) . children ( ) . length ;
150150 var result = jQuery ( '#first' ) . wrapInner ( '<div class="red"><div id="tmp"></div></div>' ) ;
151151 equals ( jQuery ( "#first" ) . children ( ) . length , 1 , "Only one child" ) ;
@@ -158,6 +158,11 @@ var testWrapInner = function(val) {
158158 equals ( jQuery ( "#first" ) . children ( ) . length , 1 , "Only one child" ) ;
159159 ok ( jQuery ( "#first" ) . children ( ) . is ( "#empty" ) , "Verify Right Element" ) ;
160160 equals ( jQuery ( "#first" ) . children ( ) . children ( ) . length , num , "Verify Elements Intact" ) ;
161+
162+ var div = jQuery ( "<div/>" ) ;
163+ div . wrapInner ( "<span></span>" ) ;
164+ equals ( div . children ( ) . length , 1 , "The contents were wrapped." ) ;
165+ equals ( div . children ( ) [ 0 ] . nodeName . toLowerCase ( ) , "span" , "A span was inserted." ) ;
161166}
162167
163168test ( "wrapInner(String|Element)" , function ( ) {
You can’t perform that action at this time.
0 commit comments