Plugin jQuery externalHTML - Astuces CSS

Anonim

innerHTML () est natif et renvoie le contenu d'un nœud DOM (par exemple, I live inside a div.externalHTML () ne l'est pas, ce qui inclurait le nœud DOM actuel (par exemple I live inside a div. ). Il s'agit d'une version jQuery pouvant être chaînée de cela.

$.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))); )