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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T07:11:24+00:00 2026-06-14T07:11:24+00:00

I have a basic string variable which stores HTML content. The html in the

  • 0

I have a basic string variable which stores HTML content.

The html in the string is a complex list like the following:

<ul>
<li>One
  <ul>
    <li>a</li>
    <li>b</li>
    <li>c</li>
  </ul>
</li>
<li>Two
  <ul>
    <li>d</li>
    <li>e</li>
    <li>f
      <ul>
        <li>g</li>
        <li>h</li>
        <li>i</li>
      </ul>
    </li>
  </ul>
</li>
<li>Three</li>

The above is a simplified example, but as you can see, the are an unknown number of list elements. A list element can contain another list. There is an unknown number of levels (a list element can have unknown (probably max 9) parent <ul>‘s.

Now when I turn this string into HTML I do the following:

var obj = $(myHTMLString);

However, this only returns the first level of list elements – So in the following for loop, only the first level is searched. I know how to search children elements (in the else section on the code), but I would require to do this for all levels of the list – which is unknown.

for (var i=0; i<obj.length;i++) {
    if ( obj[i].id == someOtherVariable ) {
        //we have found it
    }
}

Is there a way to search my html variable (obj) for all list elements?

I would like to add that when I console.log( $(myHTMLString) ); It looks like this:

screenshot

  • 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-06-14T07:11:25+00:00Added an answer on June 14, 2026 at 7:11 am

    Yes:

    var lis = $(myHTMLString).find("li");
    

    to iterate through them:

    lis.each(function(index, li){
       //do your thing. i is the index in the array, li is the li element
    })
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a basic string with holds a html table. The table looks like
Some open source libraries have tendency to re implement basic structures like string, list,
I have a very basic query string which passes a ID to a receiving
I have a basic program that compares two strings : #include <string> #include <iostream>
I have a PHP script that does basic encryption of a string through the
Maybe a basic question but let us say I have a string that is
I have a simple text reading code for Visual Basic: Dim fileReader As String
I've got some basic questions about C++. Consider the following code in which I
I have a global variable: const std::string whiteSpaceBeforeLeadingCmntOption = WhiteSpaceBeforeLeadingComment; When I remove the
I have a variable that is posted through a html form: $_POST['ref'] And a

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.