我有这个:
<div>content element</div> <div class="accordionTrigger"> <div><h1>title</h1></div> <p>text</p> <p>text</p> <p>text</p> ... </div> <div>content element</div> <div>content element</div>
我需要将所有p标签包装在一个div中,如下所示:
<div>content element</div> <div class="accordionTrigger"> <div><h1>title</h1></div> <div class="moreInfo"> <p>text</p> <p>text</p> <p>text</p> ... </div> </div> <div>content element</div> <div>content element</div>
可以用jQuery来完成吗?
如果我有不止一个< div class =“accordionTrigger”>< / div>,像这样:
<div>content element</div> <div class="accordionTrigger"> <div><h1>title</h1></div> <p>text</p> <p>text</p> ... </div> <div>content element</div> <div class="accordionTrigger"> <div><h1>title</h1></div> <p>text</p> <p>text</p> ... </div>
结果将是:
<div>content element</div> <div class="accordionTrigger"> <div><h1>title</h1></div> <p>text</p> <p>text</p> <p>text</p> <p>text</p> ... </div> <div>content element</div> <div class="accordionTrigger"> <div><h1>title</h1></div> </div>
我可以避免吗?