この質問を投稿することは非常に恥ずかしいですが、その必要性のために Jquery で unwrap または replaceWith メソッドを使用することができませんでした。
私の問題は単純です。これらのノードの子を失うことなく、html コードのいくつかのノード (jquery セレクター) を削除する必要があります。
これは、私の目標に到達するために使用された見苦しいコードの結果を示す Jsfiddle ですhttps://jsfiddle.net/uddaeh1u/15/ (はい、動作します...)
// 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;
}
});
(unwrap メソッドを使用して) 本当に良いコードを見つけてもらえますか?
本当にありがとうございました :)