
Untitled
By: a guest on
May 7th, 2012 | syntax:
None | size: 0.79 KB | hits: 14 | expires: Never
How to get Dom object's content include itself?
<div id="post">
<div>content</div>
<div>
<div></div>
$("#post")[0].outerHTML
var html = $("<div>").append($("#post").clone()).html();
$('#post').clone().wrap('<div>').parent().html();
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;
}
});
}
var elem = $("#post").clone().wrap('<div>').parent().html();