Jquery 使用.replaceWith删除<;p>;标记,但将内容保留在标记内?
我有一个表单元格,其中包含用Jquery 使用.replaceWith删除<;p>;标记,但将内容保留在标记内?,jquery,css,html-table,Jquery,Css,Html Table,我有一个表单元格,其中包含用标记包装的内容: <td class=" address"><p> Content goes here </p></td> 尝试: 示例:(使用div代替td,但概念应相同) 说明: 获取段落标记内的元素(包括文本元素),然后调用这些文本元素,删除父p标记 $(function() { $("td.address > p").contents().unwrap(); }); 我会使用这个方法 从
标记包装的内容:
<td class=" address"><p>
Content goes here
</p></td>
尝试:
示例:(使用div
代替td
,但概念应相同)
说明:
获取段落标记内的元素(包括文本元素),然后调用这些文本元素,删除父p
标记
$(function() {
$("td.address > p").contents().unwrap();
});
我会使用这个方法
从DOM中删除匹配元素集的父元素,保留匹配元素。@Ericmathewturano:没问题!很高兴为您提供帮助。很抱歉,由于意外单击而出现负面消息。
$('.address p').replaceWith('');
$('.address p').contents().unwrap();
$(function() {
$("td.address > p").contents().unwrap();
});
$('.address p').replaceWith(function() {
return $(this).html();
});
$('p').contents().unwrap();