jquery.outerhtml.js 469 B

12345678910111213141516
  1. /**
  2. * 获取元素的outerHTML
  3. */
  4. $.fn.outerHTML = function() {
  5. // IE, Chrome & Safari will comply with the non-standard outerHTML, all others (FF) will have a fall-back for cloning
  6. return (!this.length) ? this : (this[0].outerHTML ||
  7. (function(el) {
  8. var div = document.createElement('div');
  9. div.appendChild(el.cloneNode(true));
  10. var contents = div.innerHTML;
  11. div = null;
  12. return contents;
  13. })(this[0]));
  14. };