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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T04:54:08+00:00 2026-05-19T04:54:08+00:00

I have a somewhat grouping system which all the elements between two divs are

  • 0

I have a somewhat grouping system which all the elements between two divs are grouped together. See the code below to see what I’m trying to say:

$(document).ready(function(){
var groupo = $('div').filter(function(){return $(this).text().match(/\[group\]/)}); //finds "[group]"
var groupc = $('div').filter(function(){return $(this).text().match(/\[\/group\]/)}); //finds "[/group]"
groupc.addClass("groupclose"); //adds the class groupclose so that it can be used by nextUntil
 groupo.nextUntil(".groupclose").wrapAll('<div class="group"></div>');
 groupo.remove();
 groupc.remove();
});

When the HTML is:

<div>[group]</div>
<div>first</div>
<div>second</div>
<div>[/group]</div>

it works just fine, but when there are two or more ‘groups’ the wrapAll wraps them together, for example:

<div>[group]</div>
<div>first</div>
<div>second</div>
<div>[/group]</div>

<div>[group]</div>
<div>this is in</div>
<div>another group</div>
<div>which get wrapped together with the one above</div>
<div>[/group]</div>

The problem is similar to this wrapAll jQuery problem but in that case we know the number of divs in a set, while in this case we don’t.

Any ideas?

Edit: added the link to jsbin http://jsbin.com/ejepu3

  • 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-19T04:54:08+00:00Added an answer on May 19, 2026 at 4:54 am

    I think you just needed to loop through the contents of groupo. Also, no need to use filter(). You can use the :contains('') selector

    var groupo = $("div:contains('[group]')");
    var groupc = $("div:contains('[/group]')").addClass("groupclose");
    
    $(groupo).each(function(){
        $(this).nextUntil(".groupclose").wrapAll('<div class="group"></div>');
    });
    
    groupo.remove();
    groupc.remove();
    

    working version: http://jsfiddle.net/48Pfp/2/

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

Sidebar

Related Questions

I have somewhat of a thought question regarding jQuery Ajax. My question is this:
I do have somewhat of a feeling that people will try to beat me
I have a somewhat complex SQL query that is pulling from a table of
I have a somewhat unique request. What I am looking to do is listen
I have a somewhat complex plot task in matplotlib that requires--I think--an autoscale() function
I have a somewhat simple query in SQL that I would like to convert
I have a (somewhat) simple question about android. I have some classes that contain
I have a somewhat large server process written in .net-3.5, that is, running in
I am working with the Java Calendar class to do the following: Set a
I am using nokogiri and ruby to script some deployment scripts and I need

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.