File tree Expand file tree Collapse file tree 2 files changed +30
-6
lines changed
Expand file tree Collapse file tree 2 files changed +30
-6
lines changed Original file line number Diff line number Diff line change @@ -63,12 +63,11 @@ jQuery.fn.extend({
6363 } ) ;
6464 } ,
6565
66- unwrap : function ( ) {
67- return this . parent ( ) . each ( function ( ) {
68- if ( ! jQuery . nodeName ( this , "body" ) ) {
69- jQuery ( this ) . replaceWith ( this . childNodes ) ;
70- }
71- } ) . end ( ) ;
66+ unwrap : function ( selector ) {
67+ this . parent ( selector ) . not ( "body" ) . each ( function ( ) {
68+ jQuery ( this ) . replaceWith ( this . childNodes ) ;
69+ } ) ;
70+ return this ;
7271 }
7372} ) ;
7473
Original file line number Diff line number Diff line change @@ -298,6 +298,31 @@ test( "unwrap()", function() {
298298 jQuery ( "body > span.unwrap" ) . remove ( ) ;
299299} ) ;
300300
301+ test ( "unwrap( selector )" , function ( ) {
302+
303+ expect ( 5 ) ;
304+
305+ jQuery ( "body" ) . append ( " <div id='unwrap' style='display: none;'> <div id='unwrap1'> <span class='unwrap'>a</span> <span class='unwrap'>b</span> </div> <div id='unwrap2'> <span class='unwrap'>c</span> <span class='unwrap'>d</span> </div> </div>" ) ;
306+
307+ // Shouldn't unwrap, no match
308+ jQuery ( "#unwrap1 span" ) . unwrap ( "#unwrap2" ) ;
309+ equal ( jQuery ( "#unwrap1" ) . length , 1 , "still wrapped" ) ;
310+
311+ // Shouldn't unwrap, no match
312+ jQuery ( "#unwrap1 span" ) . unwrap ( "span" ) ;
313+ equal ( jQuery ( "#unwrap1" ) . length , 1 , "still wrapped" ) ;
314+
315+ // Unwraps
316+ jQuery ( "#unwrap1 span" ) . unwrap ( "#unwrap1" ) ;
317+ equal ( jQuery ( "#unwrap1" ) . length , 0 , "unwrapped match" ) ;
318+
319+ // Check return values
320+ deepEqual ( jQuery ( "#unwrap2 span" ) . get ( ) , jQuery ( "#unwrap2 span" ) . unwrap ( "quote" ) . get ( ) , "return on unmatched unwrap" ) ;
321+ deepEqual ( jQuery ( "#unwrap2 span" ) . get ( ) , jQuery ( "#unwrap2 span" ) . unwrap ( "#unwrap2" ) . get ( ) , "return on matched unwrap" ) ;
322+
323+ jQuery ( "body > span.unwrap" ) . remove ( ) ;
324+ } ) ;
325+
301326test ( "jQuery(<tag>) & wrap[Inner/All]() handle unknown elems (#10667)" , function ( ) {
302327
303328 expect ( 2 ) ;
You can’t perform that action at this time.
0 commit comments