Select different elements with wrapAll — jQuery

前端 未结 2 1239
栀梦
栀梦 2021-01-16 13:45

I am trying to wrap both a h1 tag and multiple p tags into one div using jQuery wrapAll.

Here is my HTML:

<         


        
相关标签:
2条回答
  • 2021-01-16 14:11

    Try

    $('h1').nextUntil('div.img').addBack().wrapAll('<div class="first-col" />');
    

    Demo: Fiddle

    0 讨论(0)
  • 2021-01-16 14:24

    Have you tried to just add p inside the selector:

    $('.postwrap').each(function(){
        $(this).find('h1, p').wrapAll('<div class="first-col" />');
        $(this).find('.img').wrapAll('<div class="second-col" />');
    });
    
    0 讨论(0)
提交回复
热议问题