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

  • Home
  • SEARCH
  • 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

Ask A Question

Stats

  • Questions 193k
  • Answers 193k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I would wrap the whole thing in an update panel,… May 12, 2026 at 6:40 pm
  • Editorial Team
    Editorial Team added an answer Try Python. Use BeautifulSoup to parse the HTML. The textwrap… May 12, 2026 at 6:40 pm
  • Editorial Team
    Editorial Team added an answer You need to create a class that implements IDisposable interface… May 12, 2026 at 6:40 pm

Related Questions

I am using Zend Gdata to interface with the YouTube API from a PHP
OSGi cannot find my DLL file, and I can't seem to figure out why.
I am trying to get the number of students enrolled in courses via a
I have been using PHP for a while but I am not too too
I am downloading a CSV file from another server as a data feed from

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.