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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T15:36:35+00:00 2026-05-12T15:36:35+00:00

I am using a vendor-supplied API that uses javascript to output HTML that essentially

  • 0

I am using a vendor-supplied API that uses javascript to output HTML that essentially looks like this:

<li class="parent_class"> <a href="link1.html"> Parent Name </a> </li>

<div class="child_class"> 

<li> <a href="link2.html"> Child Name 1 </a> </li>

<li> <a href="link3.html"> Child Name 2 </a> </li>

</div>

 <li class="parent_class"> <a href="link4.html"> Parent Name 2</a> </li>

<div class="child_class"> 

<li> <a href="link5.html"> Child Name 1 </a> </li>

<li> <a href="link6.html"> Child Name 2 </a> </li>

</div>

And so on. This is the code I’m going for:

<li class="parent_class"> <a href="link1.html"> Parent Name </a> 

<ul id="xc"> 

<li> <a href="link2.html"> Child Name 1 </a> </li>

<li> <a href="link3.html"> Child Name 2 </a> </li>

</ul> </li>

 <li class="parent_class"> <a href="link4.html"> Parent Name 2</a> </li>

<ul id="1"> 

<li> <a href="link5.html"> Child Name 1 </a> </li>

<li> <a href="link6.html"> Child Name 2 </a> </li>

</ul></li>

(Just in case it is useful: I will be putting a <ul> tag before the API call and a </ul> tag after it to close up the whole list.)

Using more javascript, I’ve figured out how to replace the </div> with the </ul></li> using regular expression replace, but I’m not sure how to replace the </li><div> tags with the <ul> tags, because those need to be different every time. The first <ul> MUST be <ul id="xc"> (due to even more code I don’t have control over). The other <ul>s must each have an ID, but those can be randomly generated.

I have a vague idea that I can use the exec method to create an array of all instances of </li></div>, set array[0] to <ul id="xc"> and then set array[1] to <ul id="1">, array[2] to <ul id="2"> and so on, but I’m not sure if that’s a good idea (or how exactly to do it).

Thanks in advance.

  • 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-12T15:36:36+00:00Added an answer on May 12, 2026 at 3:36 pm

    Assuming you receive the HTML as a string (as opposed to a document), you can convert it using this function:

    function mogrify (input) {
        // 1) replace </li><div> with <ul>
        var i = 0;
        var out = input.replace(/<\/li>\s*<div[^>]*>/g, function () {
            var listID = i == 0
                       ? "xc"
                       : "xc_" + (Math.floor(Math.random() * 1e9) + 1);
            ++i;
            return '<ul class="' + listID + '">';
        });
    
        // 2) replace </div> with </ul></li>, like you described:
        return out.replace(/<\/div>/g, "</ul></li>");
    }
    

    Note that the input HTML is syntactically invalid, as is using bare numbers as ID attributes.

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

Sidebar

Related Questions

I am using box-sizing with vendor prefixes, like this ...running it through the CSS
I have a link that uses javascript to submit a form, like so: <a
I am looking for a workaround way to improvise -moz-element() using -vendor-canvas() to essentially
Does using the ADO.NET Provider that a DB vendor wrote eliminate the need to
I am using C# and Visual Studio 2008. I have a class that will
I am using phpMyAdmin from a website vendor. It seems that i can not
I'm using two commercial libraries that are produced by the same vendor, called VendorLibA
I'm using vendor prefixed css transitions, based on this demo , which seems to
I'm using a well known vendor's API with a WSDL link1 , link2 (click
I'm using a vendor API to obtain a JDBC connection to the application's database.

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.