jQuery删除div两侧的标签 [英] jQuery remove tags either side of a div

查看:116
本文介绍了jQuery删除div两侧的标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何删除该div之外的p标签(我不是要删除测试div).

How can I remove the p tags outside of this div (I do not want to remove the test div).

<p>
  <div class='test'>
    content here
    <img />
  </div>
</p>

我想要的结果是...

The result I'd like would be...

<div class='test'>
  content here
  <img />
</div>

我知道这里有一个类似的问题: jQuery:我该怎么办删除周围的div标签?,但在我的情况下无法正常工作

I know there's a similar question here: jQuery: How do I remove surrounding div tags?, but not got it to work in my situation

我尝试过

$('p .test').replaceWith($('.test));

但是,当然,只是选择了sal-slideshow div,而不是之前的p.

But of course that just selects the salon-slideshow div, rather than the p before it.

推荐答案

这可以做到,但请记住,它将影响所有使用class="test"

This will do it but remember that it will affect all divs with class="test"

$("div.test").unwrap();

这篇关于jQuery删除div两侧的标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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