Remove duplicate/unnecessary tags with jQuery
I'm trying to build my own simple rich editor, so far so good.
I want to clean up my code somehow by removing unnecessary tags.
I want to transform:
<div id="text"><b><b><b>This</b> is &开发者_如何学JAVAlt;/b>a messy</b> code</div>
Into:
<div id="text"><b>This is a messy</b> code</div>
The same goes for other tags like <i>
, <u>
etc.
$('b').find('b').unwrap();
$('i').find('i').unwrap();
$('u').find('u').unwrap();
Or more concisely:
$('b b, u u, i i').unwrap();
I wouldn't use jquery for this. Instead, i'd use a server side tool to clean it up, which will depend on the platform and technology you're using server side.
One example would be Html Tidy
精彩评论