In jQuery possiamo eliminare tutto il contenuto di un elemento ad eccezione di un elemento specifico.
La soluzione รจ la seguente:
"use strict";
(function( $ ) {
$.fn.emptyExcept = function( selector ) {
return this.each(function() {
var $element = $( this ),
target = $element.find( selector )[0].outerHTML;
$element.empty().html( target );
});
};
})( jQuery );