In Jquery how to remove nested tags in specific tags but keep the text and pictures that are in depth?

Good day,

There is a tag div with the class .editor, inside of which is cleaning:

Please delete tags styleif the tag is not an image

Nesting nested unnecessary tags may varioface (As will generate a visual editor, which is needed only for loading and positioning images in the text).

Interest as of:

<div class="editor">
<p>
 <img style="float:left">
</p><p>
<span>
<font>
 1
</font>
</span>
</p>
<p></p>
<p>
</p><p>
 <img style="float:left">
<span>
<font>
 Text 3
</font>
</span>
</p>
<p></p>
the <ul>
the <li>
<span>
<font>
 <p>Text 3</p>
</font>
</span>
</li>
the <li>
<font>
 <p>Text 4</p>
</font>
</li>
</ul>
</div>


To this:

<div class="editor">
<p>
 <img style="float:left">
 1
</p>
<p></p>
<p>
</p><p>
 <img style="float:left">
 Text 2
</p>
<p></p>
the <ul>
the <li>
 Text 3
</li>
the <li>
 Text 4
</li>
</ul>
</div>


Ie it is necessary to clean all:
$('.editor > p')
$('.editor > ul > li')
$('.editor > h[1-6]')


It is important that pictures, no matter what nesting level they were, was not removed.

Can someone else cleaned result of visual editors?)
July 9th 19 at 11:13
1 answer
July 9th 19 at 11:15
Solution
var html = $('.editor').html();
html.replace(/regular expression for unwanted tags/, ");
$('.editor').html(html);


$('.editor > *').each( function(){
 var images = $(this).find('img').detach();
 var text = $(this).text();
 $(this).html( text ).prepend( images );
});
Thank you, I found this expression: (/<\/?[^>]+>/g,")); but it applies to all tags, and how to make on span and font only? - dudley_Ri commented on July 9th 19 at 11:18
: /<\/?(font|span)[^>]*>/g - cleve_Murray commented on July 9th 19 at 11:21
: Thank you! - dudley_Ri commented on July 9th 19 at 11:24

Find more questions by tags jQuery