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

  • SEARCH
  • Home
  • 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 710317
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T04:36:27+00:00 2026-05-14T04:36:27+00:00

I have a set of selected elements in jQuery: <div class=element></div> <div class=element></div> <div

  • 0

I have a set of selected elements in jQuery:

<div class="element"></div>
<div class="element"></div>
<div class="element"></div>
<div class="element"></div>
<div class="element"></div>
<div class="element"></div>
<div class="element"></div>
<div class="element"></div>
<div class="element"></div>
<div class="element"></div>
<div class="element"></div>
<div class="element"></div>

I would like to wrap these elements into groups of five like so:

<div class="wrapper">
    <div class="element"></div>
    <div class="element"></div>
    <div class="element"></div>
    <div class="element"></div>
    <div class="element"></div>
</div>
<div class="wrapper">
    <div class="element"></div>
    <div class="element"></div>
    <div class="element"></div>
    <div class="element"></div>
    <div class="element"></div>
</div>
<div class="wrapper">
    <div class="element"></div>
    <div class="element"></div>
</div>

Is there an efficient/easy way to do this? I imagine it would look something like this:

$('.element').wrapAll('<div class="wrapper"></div>');

But with a selector that selects the elements in groups of five.

Thanks!

  • 1 1 Answer
  • 1 View
  • 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-14T04:36:27+00:00Added an answer on May 14, 2026 at 4:36 am

    You can do it a bit mote compact like this:

    var elems = $('.element');
    for(var i = 0; i <= elems.length; i+=5) {
      elems.slice(i, i+5).wrapAll('<div class="wrapper"></div>');
    }
    

    This results in the exact result you have in the question 🙂 You can make that 5 a variable and wrap the number of children you want, the remainder (in this case the last 2) will be wrapped in their own wrapper at the end.

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

Sidebar

Related Questions

I am building menu with jquery, and I have set active class to selected
I have a form with elements like: <div class=row1> <select name=someSelectField multiple=multiple class=selectList> <option
Say I have 4 div elements with class .navlink , which, when clicked, use
I have set the Timeout property of SmtpClient class, but it doesn't seem to
I have a form that adds an error class to the parent div for
I have a page containing a set of jQuery tabs. All the tabs point
I am trying to use JQuery to select the next element in a set
I have a set of dijit.form.RadioButton elements. I need to be this set as
Let's assume i have HTML markup like this: <body> <div id=content> <div id=sidebar> </div>
I have a element that is set to contain a table element. The table

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.