解开div jquery中的所有段落标记

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)

提前致谢.

Mil*_*war 3

您需要解开 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)

工作演示