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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T02:34:40+00:00 2026-06-01T02:34:40+00:00

I have a markup like this: <div class=sentence> <ul title=list 3> <li> <ul title=list

  • 0

I have a markup like this:

<div class="sentence">
    <ul title="list 3">
        <li>
            <ul title="list 1">
                <li> A </li>
                <li> B </li>
            </ul>
        </li>
        <li>
            <ul title="list 2">
                <li> 1 </li>
                <li> 2 </li>
            </ul>
        </li>
    </ul>
    <ul title="list n">
             .....
    </ul>
</div>

I have a function that makes some changes into the elements inside the list. This function is quite large, so to illustrate the problem it could simplify to something like this:

$("div.sentence ul").each(function() {
    var mid = $(this).children("li").map(function() {
        return $(this).text();
    }).get().join(',');
    $(this).replaceWith(mid);
});

As you can see, this function has no sense. That’s just an example in order to show some example. Probably, that doesn’t work.

The problem is that function works only when I have only a list (ul). When I have more than one list it doesn’t work because $("div.sentence ul") returns a list of ul elements where the first one is the outer ul and the last one is the last one in reading order (I believe, also I don’t know if this order is guaranted or if it will change in the next Jquery version).

The question is I need to get first the inner lists (not a problem the order) and then the outer ones. For instance, in this example, I need to get the list tittled “list 1”, then “list 2” and the last one should be “list 3”. Is possible to get the *ul*s in this order?

  • 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-01T02:34:41+00:00Added an answer on June 1, 2026 at 2:34 am

    Take a look at this JSFiddle.

    Basically, you need a Depth-first traversal (Postorder).

    I played a bit with the selectors, mainly with the child-selector to get only the children of the next level, not all until the leaves, this for every ul:

    function foo(ctx) {
      $(ctx).find(">ul").each(function() {
          foo($(">li", this));
          alert($(this).attr('title'));
      });
    }
    
    foo("div.sentence");​
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a html markup with some <div> elements like this: <div id=1 class=classic>i
I have some markup like this: <p><a id=1 href=#>Link 1</a></p> <p id=1show class=starthidden>Hi! I
I have a markup like this: <div class=classA classB>the content</div> What I would like
I have a submit button with a markup like this: <li class=button><div class=button> <input
I have this markup: <div id=container> <h1>Heading</h1> <p>Some text</p> <div class=foo>Some stuff</div> <div class=foo>Some
I have HTML markup like this: <div id=blocks> <div class=block></div> <div class=block></div> <div class=block></div>
I have my markup like this (for argument's sake) <div id=content></div> <div id=layout></div> <div
I have the following HTML markup: <body> <div class=wrapper> <div class=head> <p class=title>title</p> <a
I have this markup x 3: <div class=features> <span class=overlay><img src=img/webdesign.png /></span> <h2>Web Design</h2>
Say i have this markup: <div class='current'> </div> <div class='current'> </div> <div class='current'> </div>

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.