jQuery/js wrap near div with same classes into single divUsing jQuery to center a DIV on the screenCreating a div element in jQueryHow can I select an element with multiple classes in jQuery?Get class list for element with jQueryHow to replace innerHTML of a div using jQuery?Use jQuery to hide a DIV when the user clicks outside of itjQuery multiple events to trigger the same functionjQuery to loop through elements with the same classHTML5 best practices; section/header/aside/article elementsWrapping multiple elements in a div using jQuery

How can I deal with my CEO asking me to hire someone with a higher salary than me, a co-founder?

How does a refinance allow a mortgage to be repaid?

How to Prove P(a) → ∀x(P(x) ∨ ¬(x = a)) using Natural Deduction

Can a virus destroy the BIOS of a modern computer?

Placement of More Information/Help Icon button for Radio Buttons

Does the Idaho Potato Commission associate potato skins with healthy eating?

Was the Stack Exchange "Happy April Fools" page fitting with the '90's code?

Finitely generated matrix groups whose eigenvalues are all algebraic

What are the G forces leaving Earth orbit?

How can saying a song's name be a copyright violation?

Sums of two squares in arithmetic progressions

What is the fastest integer factorization to break RSA?

Is it a bad idea to plug the other end of ESD strap to wall ground?

Do creatures with a listed speed of "0 ft., fly 30 ft. (hover)" ever touch the ground?

Could the museum Saturn V's be refitted for one more flight?

Are British MPs missing the point, with these 'Indicative Votes'?

Rotate ASCII Art by 45 Degrees

What exactly is ineptocracy?

Why do I get negative height?

Am I breaking OOP practice with this architecture?

Why was Sir Cadogan fired?

Is this draw by repetition?

OP Amp not amplifying audio signal

How badly should I try to prevent a user from XSSing themselves?



jQuery/js wrap near div with same classes into single div


Using jQuery to center a DIV on the screenCreating a div element in jQueryHow can I select an element with multiple classes in jQuery?Get class list for element with jQueryHow to replace innerHTML of a div using jQuery?Use jQuery to hide a DIV when the user clicks outside of itjQuery multiple events to trigger the same functionjQuery to loop through elements with the same classHTML5 best practices; section/header/aside/article elementsWrapping multiple elements in a div using jQuery













6















I have the following structure and I need to wrap the div around .item.
In some place there is two items and in some place there is single item:



<div class="section">
<div class="heading"></div>
<div class="item"></div>
<div class="item"></div>
<div class="heading"></div>
<div class="item"></div>
<div class="item"></div>
<div class="heading"></div>
<div class="item"></div>
<div class="heading"></div>
<div class="item"></div>
<div class="item"></div>
</div>


I need output in this format:



<div class="section">
<div class="heading"></div>
<div>
<div class="item"></div>
<div class="item"></div>
</div>
<div class="heading"></div>
<div>
<div class="item"></div>
<div class="item"></div>
</div>
<div class="heading"></div>
<div>
<div class="item"></div>
</div>
<div class="heading"></div>
<div>
<div class="item"></div>
<div class="item"></div>
</div>
</div>


I tried with the following code but it wraps all code to single class.



var classes = ;
$(".section > div").each(function()
classes[$(this).attr("class")] = true;
);
for (singleClass in classes)
$("." + singleClass).wrapAll('<div class="item" />');










share|improve this question




























    6















    I have the following structure and I need to wrap the div around .item.
    In some place there is two items and in some place there is single item:



    <div class="section">
    <div class="heading"></div>
    <div class="item"></div>
    <div class="item"></div>
    <div class="heading"></div>
    <div class="item"></div>
    <div class="item"></div>
    <div class="heading"></div>
    <div class="item"></div>
    <div class="heading"></div>
    <div class="item"></div>
    <div class="item"></div>
    </div>


    I need output in this format:



    <div class="section">
    <div class="heading"></div>
    <div>
    <div class="item"></div>
    <div class="item"></div>
    </div>
    <div class="heading"></div>
    <div>
    <div class="item"></div>
    <div class="item"></div>
    </div>
    <div class="heading"></div>
    <div>
    <div class="item"></div>
    </div>
    <div class="heading"></div>
    <div>
    <div class="item"></div>
    <div class="item"></div>
    </div>
    </div>


    I tried with the following code but it wraps all code to single class.



    var classes = ;
    $(".section > div").each(function()
    classes[$(this).attr("class")] = true;
    );
    for (singleClass in classes)
    $("." + singleClass).wrapAll('<div class="item" />');










    share|improve this question


























      6












      6








      6








      I have the following structure and I need to wrap the div around .item.
      In some place there is two items and in some place there is single item:



      <div class="section">
      <div class="heading"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="heading"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="heading"></div>
      <div class="item"></div>
      <div class="heading"></div>
      <div class="item"></div>
      <div class="item"></div>
      </div>


      I need output in this format:



      <div class="section">
      <div class="heading"></div>
      <div>
      <div class="item"></div>
      <div class="item"></div>
      </div>
      <div class="heading"></div>
      <div>
      <div class="item"></div>
      <div class="item"></div>
      </div>
      <div class="heading"></div>
      <div>
      <div class="item"></div>
      </div>
      <div class="heading"></div>
      <div>
      <div class="item"></div>
      <div class="item"></div>
      </div>
      </div>


      I tried with the following code but it wraps all code to single class.



      var classes = ;
      $(".section > div").each(function()
      classes[$(this).attr("class")] = true;
      );
      for (singleClass in classes)
      $("." + singleClass).wrapAll('<div class="item" />');










      share|improve this question
















      I have the following structure and I need to wrap the div around .item.
      In some place there is two items and in some place there is single item:



      <div class="section">
      <div class="heading"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="heading"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="heading"></div>
      <div class="item"></div>
      <div class="heading"></div>
      <div class="item"></div>
      <div class="item"></div>
      </div>


      I need output in this format:



      <div class="section">
      <div class="heading"></div>
      <div>
      <div class="item"></div>
      <div class="item"></div>
      </div>
      <div class="heading"></div>
      <div>
      <div class="item"></div>
      <div class="item"></div>
      </div>
      <div class="heading"></div>
      <div>
      <div class="item"></div>
      </div>
      <div class="heading"></div>
      <div>
      <div class="item"></div>
      <div class="item"></div>
      </div>
      </div>


      I tried with the following code but it wraps all code to single class.



      var classes = ;
      $(".section > div").each(function()
      classes[$(this).attr("class")] = true;
      );
      for (singleClass in classes)
      $("." + singleClass).wrapAll('<div class="item" />');







      javascript jquery html jquery-selectors






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited yesterday









      Kamil Kiełczewski

      13.9k87397




      13.9k87397










      asked yesterday









      MukeyshMukeysh

      74110




      74110






















          3 Answers
          3






          active

          oldest

          votes


















          4














          Loop through .heading elements using .each() and in loop select .item that is next to each other using .nextUntil() and then wrap them using .wrapAll()






          $(".heading").each(function()
          $(this).nextUntil(".heading").wrapAll("<div></div>");
          );

          .heading + div background: #ccc

          <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
          <div class="section">
          <div class="heading">heading</div>
          <div class="item">item</div>
          <div class="item">item</div>
          <div class="heading">heading</div>
          <div class="item">item</div>
          <div class="item">item</div>
          <div class="heading">heading</div>
          <div class="item">item</div>
          <div class="heading">heading</div>
          <div class="item">item</div>
          <div class="item">item</div>
          </div>








          share|improve this answer

























          • Maybe add a way to actually see the output...

            – Jack Bashford
            yesterday


















          2














          try



          let h,s= document.querySelector('.section');

          [...s.children].forEach(e=>
          if(e.className=='heading')
          h=document.createElement("div")
          e.insertAdjacentElement('afterend',h)
          else
          h.appendChild(e)

          )





          function change() 
          let h,s= document.querySelector('.section');

          [...s.children].forEach(e=>
          if(e.className=='heading')
          h=document.createElement("div")
          e.insertAdjacentElement('afterend',h)
          else
          h.appendChild(e)

          )

          div margin-left: 30px;

          <button onclick="change()">Click here to change</button>

          <div class="section">
          <div class="heading">head 1</div>
          <div class="item">item 1</div>
          <div class="item">item 2</div>
          <div class="heading">head 2</div>
          <div class="item">item 3</div>
          <div class="item">item 4</div>
          <div class="heading">head 3</div>
          <div class="item">item 5</div>
          <div class="heading">head 4</div>
          <div class="item">item 6</div>
          <div class="item">item 7</div>
          </div>








          share|improve this answer

























          • Your code put .items in .section

            – Mohammad
            yesterday











          • @Mohammad no - check in chrome console

            – Kamil Kiełczewski
            yesterday











          • Also doesn't work as OP want

            – Mohammad
            yesterday












          • I correct answer

            – Kamil Kiełczewski
            yesterday


















          -1














          1. Use nextUntil() with warpAll()




          $(".heading").each(function() 
          $(this).nextUntil(".heading").wrapAll("<div class='red'></div>")
          );

          .red 
          border: red 1px solid

          <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
          <div class="section">
          <div class="heading">1</div>
          <div class="item">2</div>
          <div class="item">3</div>
          <div class="heading">4</div>
          <div class="item">5</div>
          <div class="item">6</div>
          <div class="heading">7</div>
          <div class="item">8</div>
          <div class="heading">9</div>
          <div class="item">0</div>
          <div class="item">-</div>
          </div>








          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55448748%2fjquery-js-wrap-near-div-with-same-classes-into-single-div%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            3 Answers
            3






            active

            oldest

            votes








            3 Answers
            3






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            4














            Loop through .heading elements using .each() and in loop select .item that is next to each other using .nextUntil() and then wrap them using .wrapAll()






            $(".heading").each(function()
            $(this).nextUntil(".heading").wrapAll("<div></div>");
            );

            .heading + div background: #ccc

            <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
            <div class="section">
            <div class="heading">heading</div>
            <div class="item">item</div>
            <div class="item">item</div>
            <div class="heading">heading</div>
            <div class="item">item</div>
            <div class="item">item</div>
            <div class="heading">heading</div>
            <div class="item">item</div>
            <div class="heading">heading</div>
            <div class="item">item</div>
            <div class="item">item</div>
            </div>








            share|improve this answer

























            • Maybe add a way to actually see the output...

              – Jack Bashford
              yesterday















            4














            Loop through .heading elements using .each() and in loop select .item that is next to each other using .nextUntil() and then wrap them using .wrapAll()






            $(".heading").each(function()
            $(this).nextUntil(".heading").wrapAll("<div></div>");
            );

            .heading + div background: #ccc

            <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
            <div class="section">
            <div class="heading">heading</div>
            <div class="item">item</div>
            <div class="item">item</div>
            <div class="heading">heading</div>
            <div class="item">item</div>
            <div class="item">item</div>
            <div class="heading">heading</div>
            <div class="item">item</div>
            <div class="heading">heading</div>
            <div class="item">item</div>
            <div class="item">item</div>
            </div>








            share|improve this answer

























            • Maybe add a way to actually see the output...

              – Jack Bashford
              yesterday













            4












            4








            4







            Loop through .heading elements using .each() and in loop select .item that is next to each other using .nextUntil() and then wrap them using .wrapAll()






            $(".heading").each(function()
            $(this).nextUntil(".heading").wrapAll("<div></div>");
            );

            .heading + div background: #ccc

            <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
            <div class="section">
            <div class="heading">heading</div>
            <div class="item">item</div>
            <div class="item">item</div>
            <div class="heading">heading</div>
            <div class="item">item</div>
            <div class="item">item</div>
            <div class="heading">heading</div>
            <div class="item">item</div>
            <div class="heading">heading</div>
            <div class="item">item</div>
            <div class="item">item</div>
            </div>








            share|improve this answer















            Loop through .heading elements using .each() and in loop select .item that is next to each other using .nextUntil() and then wrap them using .wrapAll()






            $(".heading").each(function()
            $(this).nextUntil(".heading").wrapAll("<div></div>");
            );

            .heading + div background: #ccc

            <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
            <div class="section">
            <div class="heading">heading</div>
            <div class="item">item</div>
            <div class="item">item</div>
            <div class="heading">heading</div>
            <div class="item">item</div>
            <div class="item">item</div>
            <div class="heading">heading</div>
            <div class="item">item</div>
            <div class="heading">heading</div>
            <div class="item">item</div>
            <div class="item">item</div>
            </div>








            $(".heading").each(function()
            $(this).nextUntil(".heading").wrapAll("<div></div>");
            );

            .heading + div background: #ccc

            <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
            <div class="section">
            <div class="heading">heading</div>
            <div class="item">item</div>
            <div class="item">item</div>
            <div class="heading">heading</div>
            <div class="item">item</div>
            <div class="item">item</div>
            <div class="heading">heading</div>
            <div class="item">item</div>
            <div class="heading">heading</div>
            <div class="item">item</div>
            <div class="item">item</div>
            </div>





            $(".heading").each(function()
            $(this).nextUntil(".heading").wrapAll("<div></div>");
            );

            .heading + div background: #ccc

            <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
            <div class="section">
            <div class="heading">heading</div>
            <div class="item">item</div>
            <div class="item">item</div>
            <div class="heading">heading</div>
            <div class="item">item</div>
            <div class="item">item</div>
            <div class="heading">heading</div>
            <div class="item">item</div>
            <div class="heading">heading</div>
            <div class="item">item</div>
            <div class="item">item</div>
            </div>






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited yesterday

























            answered yesterday









            MohammadMohammad

            16k123766




            16k123766












            • Maybe add a way to actually see the output...

              – Jack Bashford
              yesterday

















            • Maybe add a way to actually see the output...

              – Jack Bashford
              yesterday
















            Maybe add a way to actually see the output...

            – Jack Bashford
            yesterday





            Maybe add a way to actually see the output...

            – Jack Bashford
            yesterday













            2














            try



            let h,s= document.querySelector('.section');

            [...s.children].forEach(e=>
            if(e.className=='heading')
            h=document.createElement("div")
            e.insertAdjacentElement('afterend',h)
            else
            h.appendChild(e)

            )





            function change() 
            let h,s= document.querySelector('.section');

            [...s.children].forEach(e=>
            if(e.className=='heading')
            h=document.createElement("div")
            e.insertAdjacentElement('afterend',h)
            else
            h.appendChild(e)

            )

            div margin-left: 30px;

            <button onclick="change()">Click here to change</button>

            <div class="section">
            <div class="heading">head 1</div>
            <div class="item">item 1</div>
            <div class="item">item 2</div>
            <div class="heading">head 2</div>
            <div class="item">item 3</div>
            <div class="item">item 4</div>
            <div class="heading">head 3</div>
            <div class="item">item 5</div>
            <div class="heading">head 4</div>
            <div class="item">item 6</div>
            <div class="item">item 7</div>
            </div>








            share|improve this answer

























            • Your code put .items in .section

              – Mohammad
              yesterday











            • @Mohammad no - check in chrome console

              – Kamil Kiełczewski
              yesterday











            • Also doesn't work as OP want

              – Mohammad
              yesterday












            • I correct answer

              – Kamil Kiełczewski
              yesterday















            2














            try



            let h,s= document.querySelector('.section');

            [...s.children].forEach(e=>
            if(e.className=='heading')
            h=document.createElement("div")
            e.insertAdjacentElement('afterend',h)
            else
            h.appendChild(e)

            )





            function change() 
            let h,s= document.querySelector('.section');

            [...s.children].forEach(e=>
            if(e.className=='heading')
            h=document.createElement("div")
            e.insertAdjacentElement('afterend',h)
            else
            h.appendChild(e)

            )

            div margin-left: 30px;

            <button onclick="change()">Click here to change</button>

            <div class="section">
            <div class="heading">head 1</div>
            <div class="item">item 1</div>
            <div class="item">item 2</div>
            <div class="heading">head 2</div>
            <div class="item">item 3</div>
            <div class="item">item 4</div>
            <div class="heading">head 3</div>
            <div class="item">item 5</div>
            <div class="heading">head 4</div>
            <div class="item">item 6</div>
            <div class="item">item 7</div>
            </div>








            share|improve this answer

























            • Your code put .items in .section

              – Mohammad
              yesterday











            • @Mohammad no - check in chrome console

              – Kamil Kiełczewski
              yesterday











            • Also doesn't work as OP want

              – Mohammad
              yesterday












            • I correct answer

              – Kamil Kiełczewski
              yesterday













            2












            2








            2







            try



            let h,s= document.querySelector('.section');

            [...s.children].forEach(e=>
            if(e.className=='heading')
            h=document.createElement("div")
            e.insertAdjacentElement('afterend',h)
            else
            h.appendChild(e)

            )





            function change() 
            let h,s= document.querySelector('.section');

            [...s.children].forEach(e=>
            if(e.className=='heading')
            h=document.createElement("div")
            e.insertAdjacentElement('afterend',h)
            else
            h.appendChild(e)

            )

            div margin-left: 30px;

            <button onclick="change()">Click here to change</button>

            <div class="section">
            <div class="heading">head 1</div>
            <div class="item">item 1</div>
            <div class="item">item 2</div>
            <div class="heading">head 2</div>
            <div class="item">item 3</div>
            <div class="item">item 4</div>
            <div class="heading">head 3</div>
            <div class="item">item 5</div>
            <div class="heading">head 4</div>
            <div class="item">item 6</div>
            <div class="item">item 7</div>
            </div>








            share|improve this answer















            try



            let h,s= document.querySelector('.section');

            [...s.children].forEach(e=>
            if(e.className=='heading')
            h=document.createElement("div")
            e.insertAdjacentElement('afterend',h)
            else
            h.appendChild(e)

            )





            function change() 
            let h,s= document.querySelector('.section');

            [...s.children].forEach(e=>
            if(e.className=='heading')
            h=document.createElement("div")
            e.insertAdjacentElement('afterend',h)
            else
            h.appendChild(e)

            )

            div margin-left: 30px;

            <button onclick="change()">Click here to change</button>

            <div class="section">
            <div class="heading">head 1</div>
            <div class="item">item 1</div>
            <div class="item">item 2</div>
            <div class="heading">head 2</div>
            <div class="item">item 3</div>
            <div class="item">item 4</div>
            <div class="heading">head 3</div>
            <div class="item">item 5</div>
            <div class="heading">head 4</div>
            <div class="item">item 6</div>
            <div class="item">item 7</div>
            </div>








            function change() 
            let h,s= document.querySelector('.section');

            [...s.children].forEach(e=>
            if(e.className=='heading')
            h=document.createElement("div")
            e.insertAdjacentElement('afterend',h)
            else
            h.appendChild(e)

            )

            div margin-left: 30px;

            <button onclick="change()">Click here to change</button>

            <div class="section">
            <div class="heading">head 1</div>
            <div class="item">item 1</div>
            <div class="item">item 2</div>
            <div class="heading">head 2</div>
            <div class="item">item 3</div>
            <div class="item">item 4</div>
            <div class="heading">head 3</div>
            <div class="item">item 5</div>
            <div class="heading">head 4</div>
            <div class="item">item 6</div>
            <div class="item">item 7</div>
            </div>





            function change() 
            let h,s= document.querySelector('.section');

            [...s.children].forEach(e=>
            if(e.className=='heading')
            h=document.createElement("div")
            e.insertAdjacentElement('afterend',h)
            else
            h.appendChild(e)

            )

            div margin-left: 30px;

            <button onclick="change()">Click here to change</button>

            <div class="section">
            <div class="heading">head 1</div>
            <div class="item">item 1</div>
            <div class="item">item 2</div>
            <div class="heading">head 2</div>
            <div class="item">item 3</div>
            <div class="item">item 4</div>
            <div class="heading">head 3</div>
            <div class="item">item 5</div>
            <div class="heading">head 4</div>
            <div class="item">item 6</div>
            <div class="item">item 7</div>
            </div>






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited yesterday

























            answered yesterday









            Kamil KiełczewskiKamil Kiełczewski

            13.9k87397




            13.9k87397












            • Your code put .items in .section

              – Mohammad
              yesterday











            • @Mohammad no - check in chrome console

              – Kamil Kiełczewski
              yesterday











            • Also doesn't work as OP want

              – Mohammad
              yesterday












            • I correct answer

              – Kamil Kiełczewski
              yesterday

















            • Your code put .items in .section

              – Mohammad
              yesterday











            • @Mohammad no - check in chrome console

              – Kamil Kiełczewski
              yesterday











            • Also doesn't work as OP want

              – Mohammad
              yesterday












            • I correct answer

              – Kamil Kiełczewski
              yesterday
















            Your code put .items in .section

            – Mohammad
            yesterday





            Your code put .items in .section

            – Mohammad
            yesterday













            @Mohammad no - check in chrome console

            – Kamil Kiełczewski
            yesterday





            @Mohammad no - check in chrome console

            – Kamil Kiełczewski
            yesterday













            Also doesn't work as OP want

            – Mohammad
            yesterday






            Also doesn't work as OP want

            – Mohammad
            yesterday














            I correct answer

            – Kamil Kiełczewski
            yesterday





            I correct answer

            – Kamil Kiełczewski
            yesterday











            -1














            1. Use nextUntil() with warpAll()




            $(".heading").each(function() 
            $(this).nextUntil(".heading").wrapAll("<div class='red'></div>")
            );

            .red 
            border: red 1px solid

            <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
            <div class="section">
            <div class="heading">1</div>
            <div class="item">2</div>
            <div class="item">3</div>
            <div class="heading">4</div>
            <div class="item">5</div>
            <div class="item">6</div>
            <div class="heading">7</div>
            <div class="item">8</div>
            <div class="heading">9</div>
            <div class="item">0</div>
            <div class="item">-</div>
            </div>








            share|improve this answer



























              -1














              1. Use nextUntil() with warpAll()




              $(".heading").each(function() 
              $(this).nextUntil(".heading").wrapAll("<div class='red'></div>")
              );

              .red 
              border: red 1px solid

              <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
              <div class="section">
              <div class="heading">1</div>
              <div class="item">2</div>
              <div class="item">3</div>
              <div class="heading">4</div>
              <div class="item">5</div>
              <div class="item">6</div>
              <div class="heading">7</div>
              <div class="item">8</div>
              <div class="heading">9</div>
              <div class="item">0</div>
              <div class="item">-</div>
              </div>








              share|improve this answer

























                -1












                -1








                -1







                1. Use nextUntil() with warpAll()




                $(".heading").each(function() 
                $(this).nextUntil(".heading").wrapAll("<div class='red'></div>")
                );

                .red 
                border: red 1px solid

                <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
                <div class="section">
                <div class="heading">1</div>
                <div class="item">2</div>
                <div class="item">3</div>
                <div class="heading">4</div>
                <div class="item">5</div>
                <div class="item">6</div>
                <div class="heading">7</div>
                <div class="item">8</div>
                <div class="heading">9</div>
                <div class="item">0</div>
                <div class="item">-</div>
                </div>








                share|improve this answer













                1. Use nextUntil() with warpAll()




                $(".heading").each(function() 
                $(this).nextUntil(".heading").wrapAll("<div class='red'></div>")
                );

                .red 
                border: red 1px solid

                <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
                <div class="section">
                <div class="heading">1</div>
                <div class="item">2</div>
                <div class="item">3</div>
                <div class="heading">4</div>
                <div class="item">5</div>
                <div class="item">6</div>
                <div class="heading">7</div>
                <div class="item">8</div>
                <div class="heading">9</div>
                <div class="item">0</div>
                <div class="item">-</div>
                </div>








                $(".heading").each(function() 
                $(this).nextUntil(".heading").wrapAll("<div class='red'></div>")
                );

                .red 
                border: red 1px solid

                <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
                <div class="section">
                <div class="heading">1</div>
                <div class="item">2</div>
                <div class="item">3</div>
                <div class="heading">4</div>
                <div class="item">5</div>
                <div class="item">6</div>
                <div class="heading">7</div>
                <div class="item">8</div>
                <div class="heading">9</div>
                <div class="item">0</div>
                <div class="item">-</div>
                </div>





                $(".heading").each(function() 
                $(this).nextUntil(".heading").wrapAll("<div class='red'></div>")
                );

                .red 
                border: red 1px solid

                <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
                <div class="section">
                <div class="heading">1</div>
                <div class="item">2</div>
                <div class="item">3</div>
                <div class="heading">4</div>
                <div class="item">5</div>
                <div class="item">6</div>
                <div class="heading">7</div>
                <div class="item">8</div>
                <div class="heading">9</div>
                <div class="item">0</div>
                <div class="item">-</div>
                </div>






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered yesterday









                guradioguradio

                13.9k32339




                13.9k32339



























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55448748%2fjquery-js-wrap-near-div-with-same-classes-into-single-div%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Club Baloncesto Breogán Índice Historia | Pavillón | Nome | O Breogán na cultura popular | Xogadores | Adestradores | Presidentes | Palmarés | Historial | Líderes | Notas | Véxase tamén | Menú de navegacióncbbreogan.galCadroGuía oficial da ACB 2009-10, páxina 201Guía oficial ACB 1992, páxina 183. Editorial DB.É de 6.500 espectadores sentados axeitándose á última normativa"Estudiantes Junior, entre as mellores canteiras"o orixinalHemeroteca El Mundo Deportivo, 16 setembro de 1970, páxina 12Historia do BreogánAlfredo Pérez, o último canoneiroHistoria C.B. BreogánHemeroteca de El Mundo DeportivoJimmy Wright, norteamericano do Breogán deixará Lugo por ameazas de morteResultados de Breogán en 1986-87Resultados de Breogán en 1990-91Ficha de Velimir Perasović en acb.comResultados de Breogán en 1994-95Breogán arrasa al Barça. "El Mundo Deportivo", 27 de setembro de 1999, páxina 58CB Breogán - FC BarcelonaA FEB invita a participar nunha nova Liga EuropeaCharlie Bell na prensa estatalMáximos anotadores 2005Tempada 2005-06 : Tódolos Xogadores da Xornada""Non quero pensar nunha man negra, mais pregúntome que está a pasar""o orixinalRaúl López, orgulloso dos xogadores, presume da boa saúde económica do BreogánJulio González confirma que cesa como presidente del BreogánHomenaxe a Lisardo GómezA tempada do rexurdimento celesteEntrevista a Lisardo GómezEl COB dinamita el Pazo para forzar el quinto (69-73)Cafés Candelas, patrocinador del CB Breogán"Suso Lázare, novo presidente do Breogán"o orixinalCafés Candelas Breogán firma el mayor triunfo de la historiaEl Breogán realizará 17 homenajes por su cincuenta aniversario"O Breogán honra ao seu fundador e primeiro presidente"o orixinalMiguel Giao recibiu a homenaxe do PazoHomenaxe aos primeiros gladiadores celestesO home que nos amosa como ver o Breo co corazónTita Franco será homenaxeada polos #50anosdeBreoJulio Vila recibirá unha homenaxe in memoriam polos #50anosdeBreo"O Breogán homenaxeará aos seus aboados máis veteráns"Pechada ovación a «Capi» Sanmartín e Ricardo «Corazón de González»Homenaxe por décadas de informaciónPaco García volve ao Pazo con motivo do 50 aniversario"Resultados y clasificaciones""O Cafés Candelas Breogán, campión da Copa Princesa""O Cafés Candelas Breogán, equipo ACB"C.B. Breogán"Proxecto social"o orixinal"Centros asociados"o orixinalFicha en imdb.comMario Camus trata la recuperación del amor en 'La vieja música', su última película"Páxina web oficial""Club Baloncesto Breogán""C. B. Breogán S.A.D."eehttp://www.fegaba.com

                    Vilaño, A Laracha Índice Patrimonio | Lugares e parroquias | Véxase tamén | Menú de navegación43°14′52″N 8°36′03″O / 43.24775, -8.60070

                    Cegueira Índice Epidemioloxía | Deficiencia visual | Tipos de cegueira | Principais causas de cegueira | Tratamento | Técnicas de adaptación e axudas | Vida dos cegos | Primeiros auxilios | Crenzas respecto das persoas cegas | Crenzas das persoas cegas | O neno deficiente visual | Aspectos psicolóxicos da cegueira | Notas | Véxase tamén | Menú de navegación54.054.154.436928256blindnessDicionario da Real Academia GalegaPortal das Palabras"International Standards: Visual Standards — Aspects and Ranges of Vision Loss with Emphasis on Population Surveys.""Visual impairment and blindness""Presentan un plan para previr a cegueira"o orixinalACCDV Associació Catalana de Cecs i Disminuïts Visuals - PMFTrachoma"Effect of gene therapy on visual function in Leber's congenital amaurosis"1844137110.1056/NEJMoa0802268Cans guía - os mellores amigos dos cegosArquivadoEscola de cans guía para cegos en Mortágua, PortugalArquivado"Tecnología para ciegos y deficientes visuales. Recopilación de recursos gratuitos en la Red""Colorino""‘COL.diesis’, escuchar los sonidos del color""COL.diesis: Transforming Colour into Melody and Implementing the Result in a Colour Sensor Device"o orixinal"Sistema de desarrollo de sinestesia color-sonido para invidentes utilizando un protocolo de audio""Enseñanza táctil - geometría y color. Juegos didácticos para niños ciegos y videntes""Sistema Constanz"L'ocupació laboral dels cecs a l'Estat espanyol està pràcticament equiparada a la de les persones amb visió, entrevista amb Pedro ZuritaONCE (Organización Nacional de Cegos de España)Prevención da cegueiraDescrición de deficiencias visuais (Disc@pnet)Braillín, un boneco atractivo para calquera neno, con ou sen discapacidade, que permite familiarizarse co sistema de escritura e lectura brailleAxudas Técnicas36838ID00897494007150-90057129528256DOID:1432HP:0000618D001766C10.597.751.941.162C97109C0155020