在每个h2之后用div换行内容

  • 本文关键字:div 换行 之后 h2 jquery
  • 更新时间 :
  • 英文 :


任何人都可以给我一些想法,我如何包装任何内容与<div>后每个<h2>标签,并给它一个唯一的id,用jquery完成?

我想做这个:

<h2>Test</h2>
 <div id="wrap_1"> // This is the wrapper im trying to add
   <p>Bla bla</p>
   <p>More Bla bla</p>
 </div>
<h2>Another test</h2>
 <div id="wrap_2"> // This is the wrapper im trying to add
   <p>Bla bla</p>
   <p>More Bla bla</p>
 </div>

Thanks in advance

像这样:

$('h2').each(function(index) { 
    $(this).nextUntil('h2').wrapAll('<div id="wrap' + index + '"></div>');
});
演示

最新更新