$.fn.outerHTML = function (that) { if (that) { $(this).replaceWith(that); } return document.createElement('body').appendChild(this[0].cloneNode(true)).parentNode.innerHTML; };