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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T01:37:21+00:00 2026-05-17T01:37:21+00:00

Is it possible, using Javascript and either jQuery or regular expressions, to group multiple

  • 0

Is it possible, using Javascript and either jQuery or regular expressions, to group multiple sibling list items in HTML as in the example below? I need to convert TikiWiki markup to HTML, and it uses ungrouped lists (just adjacent lines appended with #).

<li>Item 1.1</li>
<li>Item 1.2</li>
<li>Item 1.3</li>
<p>Paragraph</p>
<li>Item 2.1</li>
<li>Item 2.2</li>

To this:

<ul>
<li>Item 1.1</li>
<li>Item 1.2</li>
<li>Item 1.3</li>
</ul>
<p>Paragraph</p>
<ul>
<li>Item 2.1</li>
<li>Item 2.2</li>
</ul>

I already tried using $("li").wrapAll() and siblings(). Both failed.

There’s another approach. Here’s the regex I’m currently using to convert TikiWiki lists to HTML list items: replace(/[#](.*)\n?/g, "<li class='numbered'>$1</li>") Is it possible to match repeated patterns, and convert them accordingly to HTML as in this pseudo regex? replace(/repeat([#](.*)\n?)/g, "<ol>foreach(<li class='numbered'>$1</li>)</ol>")

  • 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-17T01:37:22+00:00Added an answer on May 17, 2026 at 1:37 am

    Here is my first hack at it. this might get you going in the right direction

        <div id='testList'>
            <li>Item 1.1</li>
            <li>Item 1.2</li>
            <li>Item 1.3</li>
            <p>Paragraph</p>
            <li>Item 2.1</li>
            <li>Item 2.2</li>
    
        </div>
    
    <script language='javascript' type='text/javascript'>
    
    $.fn.tagName = function() {
        return this.get(0).tagName;
    }
    
    $(document).ready(function() {
    
        alert($("#testList").html());
    
        $("li").each(function() {
            if ( $(this).parent().tagName() != "UL" ) {
                $(this).wrap("<ul></ul>");
                // alert($(this).parent().tagName())
            }
        })
    
        alert($("#testList").html());
    });
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using either JavaScript or jQuery, is it possible to capture a count on an
Using either JavaScript or jQuery, is it possible to capture a count on an
Is it possible to get the top position of an element using javascript/jquery ?
Is it possible to, using javascript, either create video data on the fly, or
Possible Duplicate: Using jQuery to compare two arrays I need a Javascript or jQuery
Using JavaScript, is it possible to use prototype to add a method to a
Using javascript, is it possible to get the id of an element by its
Using JavaScript SDK, it is possible to wall post with user's consent. Since It
Possible Duplicate: How can you check for a #hash in a URL using JavaScript?
Is it possible to edit a JSON file using javaScript? I'm trying to read

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.