if (!Element.prototype.hasOwnProperty("outerHTML")) { Object.defineProperty(Element.prototype, "outerHTML", { configurable: true, get: function getOuterHTML() { var html = this.innerHTML; var tag = "<" + this.tagName; var closeTag = "</" + this.tagName + ">"; [].forEach.call(this.attributes, function (attr) { tag += attr.nodeName + '="' + attr.nodeValue + '"'; }); tag += ">"; return tag + html + closeTag; } }); }
If outerHTML is not upstream, you should pin it. That means you can just do
document.getElementById("post").outerHTML;
Demo
source share