如何删除匹配的标签,但留下内容与JQuery [英] how to remove matched tags but leave content with JQuery

查看:90
本文介绍了如何删除匹配的标签,但留下内容与JQuery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的HTML:

<div>
 <div class="a">
  content1
 </div>
 content 2
 <div class="a">
  <b>content 3</b>
 </div>
</div>

我想摆脱class =a的div,但保留其内容。我最初的尝试是:

and I want to get rid of the div's of class="a" but leave their content. My initial attempt was:

$("div.a").replaceWith($(this).html());

未定义。你会怎么做到这一点?

However this is undefined. How would you do this?

推荐答案

试试

try

$("div.a").each(function(){
    $(this).replaceWith($(this).html());
});

这篇关于如何删除匹配的标签,但留下内容与JQuery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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