开发者

Remove duplicate/unnecessary tags with jQuery

开发者 https://www.devze.com 2023-04-10 18:33 出处:网络
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'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

0

精彩评论

暂无评论...
验证码 换一张
取 消