Test case for jQuery Ticket 7898

replaceWith

by jitter

HTML

<div id="bla">
    <p>foo1</p>
</div>
<div id="bla2">
    <p>foo2</p>
</div>

JavaScript

jQuery.fn.extend({
    myReplaceWith: function( value ) {
        return this.each(function() {
            var next = this.nextSibling,
                parent = this.parentNode;
            jQuery(this).empty().remove();
            if (next) {
                jQuery(next).before(value);
            } else {
                jQuery(parent).append(value);
            }
        });
    }
});
alert($("#bla").replaceWith("<p>test1</p>")[0].outerHTML);
alert($("#bla2").myReplaceWith("<p>test2</p>")[0].outerHTML);