使用jQuery清理HTML代码? [英] Using jQuery to clean up HTML code?

查看:99
本文介绍了使用jQuery清理HTML代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用jQuery,没有人知道如何清理这个标记:

 < span style =font-size: 19px> 
< span style =font-size:20px>
< span style =font-size:21px>
某物
< / span>
< / span>
< / span>

...并将其转换为:

 < span style =font-size:21px> 
某物
< / span>

如果有人能指出我的方向正确,我们将不胜感激。或者如果有人知道任何可以从HTML中删除无用标记的库,那也会很棒。






UPDATE p>

上面的代码只是一个例子。可能有20个包装跨度,例如...

unwrap 所有span标签,只留下内部span标签。

  $('span')。unwrap(); 

FIDDLE


Using jQuery, does anyone know how I can clean this markup:

<span style="font-size:19px">
  <span style="font-size:20px">
    <span style="font-size:21px">
      Something
    </span>
  </span>
</span>

...and transform it into this:

<span style="font-size:21px">
  Something
</span>

If anyone can point me in the right direction, it would be greatly appreciated. Or if anyone knows of any libraries that can remove useless tags from HTML, that would be great too.


UPDATE

The above code is just an example. There could be 20 wrapped spans for example...

解决方案

Just unwrap all the span tags, that would leave only the inner span tag.

$('span').unwrap();

FIDDLE

这篇关于使用jQuery清理HTML代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆