Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 7th, 2012  |  syntax: None  |  size: 0.79 KB  |  hits: 14  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. How to get Dom object's content include itself?
  2. <div id="post">
  3.      <div>content</div>
  4. <div>
  5. <div></div>
  6.        
  7. $("#post")[0].outerHTML
  8.        
  9. var html = $("<div>").append($("#post").clone()).html();
  10.        
  11. $('#post').clone().wrap('<div>').parent().html();
  12.        
  13. if (!Element.prototype.hasOwnProperty("outerHTML")) {
  14.   Object.defineProperty(Element.prototype, "outerHTML", {
  15.     configurable: true,
  16.     get: function getOuterHTML() {
  17.       var html = this.innerHTML;
  18.       var tag = "<" + this.tagName;
  19.       var closeTag = "</" + this.tagName + ">";
  20.       [].forEach.call(this.attributes, function (attr) {
  21.         tag += attr.nodeName + '="' + attr.nodeValue + '"';
  22.       });
  23.       tag += ">";
  24.       return tag + html + closeTag;
  25.     }
  26.   });
  27. }
  28.        
  29. var elem = $("#post").clone().wrap('<div>').parent().html();