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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T23:35:12+00:00 2026-06-08T23:35:12+00:00

I have an unordered list, but there are headers within it for different categories.

  • 0

I have an unordered list, but there are headers within it for different categories.

<ul>
    <h2>header1</h2>
    <li>...</li>
    <li>...</li>
    <li>...</li>
    <li>...</li>
    <h2>header2</h2>
    <li>...</li>
</ul>

I’m trying to loop through them and order them by the date, but the headers are throwing it off.

I’m looping through using:

var list = $('#articleList');
list.children("li").each(function () {
    ...
}

and I’m using this within the loop to select the one before it:

var prev = $(this).prev("li");

For some reason, prev selects the headers if you are on the list item after the header instead of the list item before them. So my sorting ends up being correct within the headers, but I need the whole thing to be ordered, not just in sections.

  • 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-08T23:35:14+00:00Added an answer on June 8, 2026 at 11:35 pm

    This will have to do with the HTML parsing. By specification, lists may only contain <li> elements and nothing else. So, your browser will build a different DOM, e.g. by wrapping the headings into list items (HTML5 wil specify what exactly to do with invalid HTML). Use your DOM inspector to view the actual DOM tree (context menu -> Inspect element).

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

Sidebar

Related Questions

I have a unordered list <ul id=images > . There are 3 list items
I have unordered list of links and i am trying to get the clicked
I have 3 btns which are simple anchor tags within an unordered list each
I have a unordered list where every <li> has a different ID and a
I have an unordered list... <ul class=hide> <li class=home> <div class=link> <a href=/>Home</a> </div>
I have an unordered list and each list element contains a photo and a
I have an unordered list whose list items are displaying inline. However, its layout
I have an unordered list: <div class=toplist> <ul> <li>Item</li> <li>Item</li> <li>Item</li> <li>Item</li> <li>Item</li> <li>Item</li>
I have an unordered list that is a child in a smaller parent div
I have an unordered list. <style> #button1 { position:relative; z-index: 3; } #button2 {

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.