0

Example:

<div id="block">
    <div id="wrapper">
        Some content
        <p>Lorem ipsum...</p>
        Little more
    </div>
</div>

The goal is to remove #wrapper saving it's content. All jQuery data and events of #wrapper content must be saved. The content of #wrapper is unknown so neither $( '#wrapper p' ).unwrap() nor $( '#block' )[ 0 ].innerHTML += $( '#wrapper' ).html; $( '#wrapper' ).remove; are not acceptable.

Result must be:

<div id="block">
    Some content
    <p>Lorem ipsum...</p>
    Little more
</div>
Finesse
  • 9,793
  • 7
  • 62
  • 92

1 Answers1

0
var $wrapper = $( '#wrapper' );
    $contents = $wrapper.contents();

if ( $contents.length )
    $contents.first().unwrap();
else
    $wrapper.remove();
Finesse
  • 9,793
  • 7
  • 62
  • 92
  • Generally, answers are much more helpful if they include an explanation of what the code is intended to do, and why that solves the problem without introducing others. (This post was flagged by at least one user, presumably because they thought an answer without explanation should be deleted.) – Jose Ricardo Bustos M. Sep 17 '15 at 01:45