Wrap elements inside a div using jQuery Wrap elements inside a div using jQuery jquery jquery

Wrap elements inside a div using jQuery


Check the .wrapAll() method:

$('.accordionTrigger p').wrapAll('<div class="moreInfo"></div>');

The wrapAll() method will wrap all the elements matched into another element (compared to the .wrap() method which wraps the matched elements individually)

DEMO


Check this it will work out as per expectation

<div>content element</div><div class="accordionTrigger">  <div><h1>title</h1></div>  <p>text</p>  <p>text</p>  <p>text</p>  <script type="text/javascript">       $("p").wrapAll("<div class='moreinfo'/>");   </script></div><div>content element</div><div>content element</div>