Wrap elements inside a div using jQuery

前端 未结 2 991
野性不改
野性不改 2020-12-03 13:10

I have this:

content element

title

tex

相关标签:
2条回答
  • 2020-12-03 13:42

    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>
    
    0 讨论(0)
  • 2020-12-03 13:51

    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

    0 讨论(0)
提交回复
热议问题