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 8046169
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T05:43:25+00:00 2026-06-05T05:43:25+00:00

I have a dynamically generated page with varying number of items (div.item). Each item

  • 0

I have a dynamically generated page with varying number of items (div.item). Each item has an inner div with class “date”. The items are ordered by ascending order from the DB based on the date value. Since this page content taken from the DB there may be 10 items with the same date, then the next 3 will share a date, then the next X may share another date, and so on.

Based on the content of div.date I want to wrap all items with similar dates in a div.group. I would have preferred doing this direct on the PHP code, but I’ve inherited a large messy project with no documentation and this option is only temporary. The current simplified structure is below:

<div class="item">
  <div class="date">04-06-2012</div>
  <div class="other-content">Other Content</div>
</div>
<div class="item"> // To be grouped with above
  <div class="date">04-06-2012</div> 
  <div class="other-content">Other Content</div>
</div>
...
<div class="item"> // In it's own group
  <div class="date">08-06-2012</div>
  <div class="other-content">Other Content</div> 
</div>
...

Thanks

  • 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-06-05T05:43:26+00:00Added an answer on June 5, 2026 at 5:43 am

    This will group all items by date, and append the div.group elements to body.

    var groups={}
    $('div.item').each(function() {
        var dt = $(this).find ( '.date' ).text() 
        groups[dt] = groups[dt] || []
        groups[dt].push (this)
    });
    $.each (groups, function(k, v) {
        var group = $('<div/>').addClass('group')
        $.each (v, function(k, item) {
            $(item).detach().appendTo (group)
        });
        group.appendTo ( 'body' )  //or wherever you need to append it
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Have JSP page with dynamically generated HTML table with unknown number of rows. Have
I'm working on a web page where I have a dynamically generated table where
I have a page which contains a dynamically generated grid, where a user can
I have a trivia page that is dynamically generated by some javascript code. It
I have a drop down list which is dynamically generated using ajax on page
I have a dynamically generated table and for each row in the table there
Fiddle: http://jsfiddle.net/MhWm5/16/ I have some dynamically generated table rows/values with dynamic IDs <td class=control-group>
I have several a tags as shown below on a dynamically generated page <a
I have a dynamically generated CSS file. It's fairly large, and has different content
I have the following dynamically generated table on a page along with other tables

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.