使用.replaceWith删除< p>标签,但将内容保留在标签中? [英] Using .replaceWith to remove <p> tags but keep content inside tags?
本文介绍了使用.replaceWith删除< p>标签,但将内容保留在标签中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个表格单元格,其中包含< p>
标签中包含的内容:
< td class =address>< p>
内容来到这里
< / p>< / td>
我想要< p>
删除,如下所示:
< td class =address>
内容来到这里
< / td>
我试过下面的jQuery,但它没有工作。有人可以指向正确的方向吗?
$('。address p')。replaceWith('');
解决方案
尝试:
$('。address p')。contents()。unwrap();
示例: http://jsfiddle.net/6zAN7/34/ (使用 div
而不是 td
但概念应该是一样的)
说明:
p> contents
在段落标签(包括文本元素)中获取元素,然后在这些文本元素上调用 unwrap
,删除父元素 p
标记。 I have a table cell containing content that's wrapped in <p>
tags:
<td class=" address"><p>
Content goes here
</p></td>
I want the <p>
tags removed so it looks like this:
<td class=" address">
Content goes here
</td>
I tried the following jQuery, but it didn't work. Can someone point me in the right direction?
$('.address p').replaceWith('');
解决方案
Try:
$('.address p').contents().unwrap();
Example: http://jsfiddle.net/6zAN7/34/ (uses div
instead of td
but the concept should be the same)
Explanation:
contents
gets elements inside the paragraph tag (including text elements), and then calls unwrap
on those text elements, removing the parent p
tag.
这篇关于使用.replaceWith删除< p>标签,但将内容保留在标签中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文