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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T01:23:45+00:00 2026-05-13T01:23:45+00:00

I need a nested list with subitem numbering, like this: 1. Item 1 1.1

  • 0

I need a nested list with subitem numbering, like this:

1. Item 1
  1.1 - Subitem 1
  1.2 - Subitem 2
  1.3 - Subitem 3
  1.4 - Subitem 4
  1.5 - Subitem 5
2. Item 2
  2.1 - Subitem 1
  2.2 - Subitem 2
  2.3 - Subitem 3
  2.4 - Subitem 4
  2.5 - Subitem 5

Well, I know I cannot achieve that with pure HTML. It would be great to use something like this and have the sublist automatically numbered:

<ol>
<li>
   Item 1
   <ol>
     <li>Subitem 1</li>
     <li>Subitem 2</li>
     <li>Subitem 3</li>
     <li>Subitem 4</li>
     <li>Subitem 5</li>
   </ol>
</li>
<li>
   Item 2
   <ol>
     <li>Subitem 1</li>
     <li>Subitem 2</li>
     <li>Subitem 3</li>
     <li>Subitem 4</li>
     <li>Subitem 5</li>
   </ol>
</li>
</ol>

Is there a solution for this using JavaScript or jQuery or something?

  • 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-13T01:23:45+00:00Added an answer on May 13, 2026 at 1:23 am

    If you want to do it cross-browser with jQuery:

    $("ol#list ol").each(function(i, el){
       $(this).children().each(function(ci,cel){
          $(this).prepend('<span class="pseudo-num">' + [i + 1, ci + 1].join('.') + ' </span>');
       });
    }).addClass('pseudo-processed');
    

    And in your CSS:

    ol .pseudo-num { display: none }
    ol.pseudo-processed { list-style: none; padding-left: 0 }
    ol.pseudo-processed .pseudo-num { display: inline; font-weight: bold }
    

    This is for one level only. You could alter the code to create a recursive function for multiple levels.

    This is setup to progressively enhance your page. Without Javascript it would fallback to normal nested numbering.

    UPDATE: Thanks to @Gumbo work, I reworked this code into a recursive plugin. It would use the same CSS as in my previous example, but now it is a “full fledged” jQuery plugin with support for any depth:

    $.fn.outline = function(options, counters){
        var options  = $.extend({}, $.fn.outline.defaults, options),
            counters = counters || [];
    
        this.each(function(){
           $(this).children('li').each(function(i){
               var ct = counters.concat([i + 1]);
               if(counters.length){
                 $('<span></span>')
                    .addClass(options.numberClass)
                    .text(ct.join('.') + ' ')
                    .prependTo(this);
               }
               $(this).children('ol').outline(options, ct);
           })
        });
    
        if(!counters.length) this.addClass(options.processedClass)
    }
    
    $.fn.outline.defaults = {
           numberClass: 'pseudo-num',
        processedClass: 'pseudo-processed'
    }
    

    You could then call it on a specific #id:

     $("#list").outline();
    

    Or use @Gumbo’s nice selector to apply it to all ol tags on one page:

     $("ol:not(li > ol)").outline();
    

    And you can either override the defaults globally, or on an individual basis:

     $.fn.outline.defaults.processedClass = 'ol-ready';
     // or
     $("#list").outline({processedClass: 'ol-ready'});
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I have code with nested objects like this do I need to use
Little help need with jquery sortable. I have a nested list like so: <div
Suppose I have a bulleted list like this: * list item 1 * list
I need to create this function flat that's supposed to re-contract a new list
I know that the topic of flattening a nested list has been covered in
I have two tables: Campaigns, Campaign_statistics. I need to output campaigns list with nested
I need to transform my nested sets structure (mysql) into json for this spacetree
If I need to create a couple of nested DOM elements, I know one
I have a nested JSON object that I need to loop through, and the
I'm manipulating a nested list in jquery mobile. I need to run a check

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.