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

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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T22:22:39+00:00 2026-06-07T22:22:39+00:00

Edit: My solution, based on the chosen answer: var $brs, $chunks = []; $brs

  • 0

Edit: My solution, based on the chosen answer:

var $brs, 
    $chunks = [];

$brs = $('hr:eq(1)').nextUntil($('hr:eq(2)')).filter('br');
$chunks.push($('hr:eq(1)').nextUntil($brs.eq(0)));
for (i = 0; i < $brs.length - 1; i++) {
    $chunks.push($brs.eq(i).nextUntil($brs.eq(i+1)));
}

I have an unusual case that’s resulted from a VERY poorly written website I am attempting to parse with javascript. I won’t delve into the fun parsing, but I’ve finally managed to mangle it down to a meaningful structure. I now have a DOM that looks like this (for all intents and purposes, look at this as a flat listing of tags, each closed before the next starts):

<hr>
<a>
<span class="desc">
[<a>*]      // 0 or more anchor tags can show up here
<br>
<br>
<a>
<span class="desc">
[<a>*]
<br>
<br>
.
.
.

What I am looking to do is grab each cluster of tags into its own array/jquery object/whatever by, essentially, running a .split() on the <br> tags. It is possible to do such a thing? if not, how would you go about separating this into chunks? So the result would be this:

[<a>, <span class="desc">, <a>],
[<a>, <span class="desc">],
[<a>, <span class="desc">, <a>, <a>, <a>],
[<a>, <span class="desc">],
...
  • 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-07T22:22:41+00:00Added an answer on June 7, 2026 at 10:22 pm

    I’m not sure why you’re doing that instead of just modifying the html, but it’s technically possible using the .nextUntil jQuery method.

    Starting at the hr, select all sibling elements until the first br and push the jQuery set into an array. Repeat this process between each pair of line-breaks. .eq() can be used to target a specific br.

    var $brList = $("br");
    var domArray = [];
    for(var i=0; i < $brList.length; i++){
        if(i==0){
            domArray.push($("hr").nextUntil($brList.eq(i)));
            continue;
        }
        domArray.push($brList.eq(i-1).nextUntil($brList.eq(i)));
    }
    

    Of course the specified selectors will find all br or hr elements on the page, so you will need to make your selectors more specific if there are others. You can do this by providing a context for the selector to look in.


    If you don’t want to keep the entire jQuery object in the array (though you probably do want to because you can retrieve DOM elements using the regular array methods — with the added benefit of having all of the jQuery functionality available) you can convert the jQuery object to a regular array. jQuery’s .toArray() method will take care of that for you:

    domArray.push(
        $brList.eq(i-1)
               .nextUntil($brList.eq(i))
               .toArray()
    );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Edit: Posting Solution I wanted to create color swatches based on the color chosen
Intro: EDIT: See solution at the bottom of this question (c++) I have a
Edit: I've got the solution and have described it a bit more at the
EDIT: I now have a solution, but I'd really apprecite a concise description of
EDIT : proper solution: void add(Student s) { if(root == null) root = new
Solution Edit: Turns out you can't use the PHP SDK to return the correct
[edit] Found the solution. Reinstall EVERYTHING - xcode, mono, monodevelop and monotouch. Now it
(Edit: put possible solution at end) I'm a C/C++ programmer who is learning Objective
My current solution will suck sometimes EDIT For those who don't understand,see this example:
EDIT: solved, look below for my solution. first of all, this is my very

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.