jQuery unwrapInner

http://wowmotty.blogspot.com/2012/07/jquery-unwrapinner.html

by Mottie

HTML

<button><strong>UnwrapInner - A Test Button</strong></button>
<div class="outer">
    <button>
        <span class="inner">Remove the Blue Border!</span>
    </button>
</div>

CSS

body {padding:50px;}

strong {font-weight:bold;color:red;}

.outer {border:2px solid blue;}

.inner {color:green;}

JavaScript

// unwrapInner function
// http://wowmotty.blogspot.com/2012/07/jquery-unwrapinner.html
jQuery.fn.extend({
    unwrapInner: function(selector) {
        return this.each(function() {
            var t = this,
                c = $(t).children(selector);
            if (c.length === 1) {
                c.contents().appendTo(t);
                c.remove();
            }
        });
    }
});

$('button').click(function() {
    $(this).unwrapInner('strong');
})

.next()
// this click is on the div, not the button
.click(function() {
    $(this).find('button').unwrap('.outer');
});