Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 445059
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T21:19:57+00:00 2026-05-12T21:19:57+00:00

I have another problem here. I have few repeating groups of divs. There is

  • 0

I have another problem here. I have few repeating groups of divs. There is 3 divs with different classes in one group.

What I need to do is wrap the into one ‘container’. When I’m using wrapAll it wraps all into one div.

And this is my html:

<div class="bb_box_tl"></div>
<div class="bb_box_l"></div>
<div class="bb_box_lb"></div>

<div class="bb_box_tl"></div>
<div class="bb_box_l"></div>
<div class="bb_box_lb"></div>

<div class="bb_box_tl"></div>
<div class="bb_box_l"></div>
<div class="bb_box_lb"></div>

This is all in one body.

As I result i would like to have them look like this:

<div class="box-cont">
    <div class="bb_box_tl"></div>
    <div class="bb_box_l"></div>
    <div class="bb_box_lb"></div>
</div>

<div class="box-cont">
    <div class="bb_box_tl"></div>
    <div class="bb_box_l"></div>
    <div class="bb_box_lb"></div>
</div>

<div class="box-cont">
    <div class="bb_box_tl"></div>
    <div class="bb_box_l"></div>
    <div class="bb_box_lb"></div>
</div>

Thank you for your help in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T21:19:58+00:00Added an answer on May 12, 2026 at 9:19 pm

    I wrote just the plugin for this a while ago

    (function($){
    
       $.fn.wrapChildren = function(options) {
    
        var options = $.extend({
                                  childElem : undefined,
                                  sets : 1,
                                  wrapper : 'div'
                                }, options || {});
        if (options.childElem === undefined) return this;
    
     return this.each(function() {
      var elems = $(this).children(options.childElem);
      var arr = [];
    
      elems.each(function(i,value) {
        arr.push(value);
        if (((i + 1) % options.sets === 0) || (i === elems.length -1))
       {
         var set = $(arr);
         arr = [];
         set.wrapAll($("<" + options.wrapper + ">"));
       }
      });
        });
    
      }
    
    })(jQuery);
    

    You pass in an options object defining

    • childElem – the filter selector of the immediate children to wrap
    • sets – how you want to group the child elements. For example, sets of 3 in your case. Default is 1
    • wrapper – the element to wrap the child elements in. default is <div>

    Use like so on your data. You need to define a parent element for the divs

    $(function() {   
      $('body').wrapChildren({ 
                 childElem : 'div.bb_box_tl, div.bb_box_l, div.bb_box_lb' , 
                 sets: 3, 
                 wrapper: 'div class="box-cont"'
      });   
    });
    

    Here’s a Working Demo with some data.

    UPDATE:

    I wrote a blog post with a slightly modified and improved version of this

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.