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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T16:16:19+00:00 2026-06-10T16:16:19+00:00

What I want is to be able to split an ul into two or

  • 0

What I want is to be able to split an ul into two or more pieces, whenever the class “splithere” is matched. Then I need to wrap each part in a container. Like so:

<ul class="someclass">
    <li>One</li>
    <li>Two</li>
    <li>Three</li>
    <li class="splithere">Four</li>
    <li>Five</li>
    <li>Six</li>
    <li class="splithere">Seven</li>
    <li>Eight</li>
    <li>Nine</li>
</ul>

And what I want to end up with this:

<ul class="someclass">
    <li class="newclass">
        <ul>
            <li>One</li>
            <li>Two</li>
            <li>Three</li>
        </ul>
    </li>
    <li class="newclass">
        <ul>
            <li class="splithere">Four</li>
            <li>Five</li>
            <li>Six</li>
        </ul>
    </li>
    <li class="newclass">
        <ul>
            <li class="splithere">Seven</li>
            <li>Eight</li>
            <li>Nine</li>
        </ul>
    </li>
</ul>

I hope someone can help me…

  • 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-10T16:16:20+00:00Added an answer on June 10, 2026 at 4:16 pm

    You can do it like this:

    $(".someclass .splithere, .someclass li:first").each(function() {
        var li = $('<li class="newclass"></li>').insertBefore(this);
        var ul = $("<ul>").appendTo(li);
        $(this).nextUntil(".splithere")
            .add(this)
            .appendTo(ul);
    });​
    

    Working example: http://jsfiddle.net/jfriend00/TTRhc/


    Simplified it a little more:

    $(".someclass .splithere, .someclass li:first").each(function() {
        var li = $('<li class="newclass"><ul></ul></li>').insertBefore(this);
        $(this).nextUntil(".splithere").add(this).appendTo(li.find("ul"));
    });​
    

    Working example: http://jsfiddle.net/jfriend00/bC5J9/

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

Sidebar

Related Questions

I want to split the calendar into two-week intervals starting at 2008-May-5 , or
I have a patch which I'd like to split into two patches. I need
I want to have user rights split into two. Some of the policies at
I want to be able to split csv strings in Oracle 9i I've read
I want to be able to split a big test to smaller tests so
I want to be able to split up my bin and my code files
I'm splitting a string into an array, then I want to remove the white
I would like to be able to split a string into several parts if
So basically, I'm creating a site that thats split into two columns. These columns
I decided to split a dynamic web application into two dynamic web applications, a

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.