私があなたを正しく理解していれば、ループで処理すべきでない要素を指定する必要があります。.each()その場合は、:not()セレクターまたは.not()メソッドを使用します。
$("body *:not(p,i,u,br)").each(function(){
$(this).replaceWith($(this).html());
});
// OR:
$("body *").not("p,i,u,br").each(function(){
$(this).replaceWith($(this).html());
});
// OR, encapsulated in a function with a clunky name:
function stripElementsNotSpecified(tagsToRetain) {
$("body *").not(tagsToRetain).each(function(){
$(this).replaceWith($(this).html());
});
}
stripElementsNotSpecified("p,i,u,br");
"body *"セレクターの:not(p,i,u.br)一部がないと、ドキュメントの html、head、script などの要素が選択されることに注意してください。"body *"本体の子のみを選択します。