innerHTML () là bản địa và trả về nội dung của một nút DOM (ví dụ: I live inside a div.
externalHTML () thì không, sẽ bao gồm nút DOM hiện tại (ví dụ I live inside a div.
). Đây là phiên bản jQuery có chuỗi có thể thực hiện điều đó.
$.fn.outerHTML = function()( // IE, Chrome & Safari will comply with the non-standard outerHTML, all others (FF) will have a fall-back for cloning return (!this.length) ? this : (this(0).outerHTML || ( function(el)( var div = document.createElement('div'); div.appendChild(el.cloneNode(true)); var contents = div.innerHTML; div = null; return contents; ))(this(0))); )