Has*_*aza 6 html javascript css jquery
这里我有示例html我想在div中解开所有段落标签.目前html看起来像这样.
<div class="divclass">
Hi this is some text.
<p>testing test</p>
<p></p>
<p><a href="#" rel="nofollow">Testing text2</a></p>
</div>
Run Code Online (Sandbox Code Playgroud)
但我想要这样.
<div class="divclass">
Hi this is some text.
testing test
<a href="#" rel="nofollow">Testing text2</a>
</div>
Run Code Online (Sandbox Code Playgroud)
提前致谢.
您需要解开 p 元素的内容:
$('div p').contents().unwrap();
Run Code Online (Sandbox Code Playgroud)
但是您有 p 元素,但没有内容。此类标签不会被代码删除。你需要找到兄弟姐妹 p 然后将其删除。:
$('div p').contents().unwrap().siblings('p').remove();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1549 次 |
| 最近记录: |