I am very ashamed to post this question but I have not managed to get use of unwrap or replaceWith methods in Jquery for that need.
My problem is simple : I need to remove some nodes (jquery selectors) of an html code without losing the children of these nodes.
Here is a Jsfiddle that demonstrate the result of my unsightly code used to reach my goal https://jsfiddle.net/uddaeh1u/15/ (yes it's works...)
// var content : the html source code of the wysiwyg
var result = '';
$(content).contents().each(function(){
var addContent = '';
// textNode
if(this.nodeType == 3) {
// Text Node
result+= $(this).text();
} else if(this.nodeType == 1 && $(this).hasClass('atwho-inserted')) {
// if is an Object Node with the target class
// I only keep it's contents (means that ".atwho-inserted" is not kept)
result+= $(this).html();
} else {
// in any other case I keep it entirely
result+= this.outerHTML;
}
});
Could you find me a really better code (with unwrap method) ?
Thank you a lot :)
` is also removed. Is this expected?
– n4m31ess_c0d3r Nov 10 '16 at 12:05