合并段落

sub*_*ash 2 javascript jquery

我是Jquery的新手,我的要求是将两个段落合并为单个段落.我尝试使用以下代码.

<p>This is first para text </p>
<p>This is second para text </p>
<p>This is third para text.</p>
Run Code Online (Sandbox Code Playgroud)

<p>This is first para text This is second para text This is third para text.</p>
Run Code Online (Sandbox Code Playgroud)

它不起作用.有任何想法吗?

xda*_*azz 5

只有一行代码:

$('p').contents().unwrap().wrapAll('<p>');
Run Code Online (Sandbox Code Playgroud)

看演示.

  • 这绝对是我最喜欢的方式. (2认同)