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 a somewhat messily-formatted Objective-C code base. Is there a way to have
OK, I have a somewhat complicated system in C++. In a nutshell, I need
I'm always referencing DLLs in my C# code, but they have remained somewhat of
I have somewhat deep Json structure like below incoming over the wire into C#
I have somewhat interesting development situation. The client and deployment server are inside a
Does VS2008 have somewhat C++0x standard support? DUPLICATE Visual Studio support for new C
I have a somewhat complicated branching structure at work (at least for me). It
I have several somewhat separate programs, that conceptually can fit into a single project.
I am learning about SOAP implementation and have become somewhat confused regarding the appropriate
I’ve only just started using ASP.NET MVC, and I have a somewhat trivial question:

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.