Remove duplicate / unnecessary tags with jQuery

I am trying to create my own simple editor, so good.

I want to somehow clear my code by removing unnecessary tags.

I want to convert:

<div id="text"><b><b><b>This</b> is </b>a messy</b> code</div> 

IN:

 <div id="text"><b>This is a messy</b> code</div> 

The same goes for other tags such as <i> , <u> , etc.

+4
source share
2 answers
 $('b').find('b').unwrap(); $('i').find('i').unwrap(); $('u').find('u').unwrap(); 

Or more briefly:

 $('bb, uu, i i').unwrap(); 
+7
source

I would not use jquery for this. Instead, I would use a server-side tool to clean it, which will depend on the platform and technologies that you use on the server side.

An example is Html Tidy

0
source

All Articles