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

I need to create a multi-dimensional (nested) hashtable/dictionary so that I can use syntax
Need a way to allow sorting except for last item with in a list.
Need a function like: function isGoogleURL(url) { ... } that returns true iff URL
I need to build a nested comments system in a Rails 3 application that
Need a function that takes a character as a parameter and returns true if
Need to an expression that returns only things with an I followed by either
I need to know about Epoll On linux System. Could you recommend manual or
I need to send hundreds of newsletters, but would like to check first if
I have lots of entities with nested List<> in each. For example, I have
I'm making a sub nav in wordpress and have a nested list style menu.

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.