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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T05:45:33+00:00 2026-06-06T05:45:33+00:00

i have this following html structure usilg ul and li. <ul class=treeview id=productTree> <li

  • 0

i have this following html structure usilg ul and li.

<ul class="treeview" id="productTree">
   <li class="collapsable lastCollapsable">
     <div class="hitarea collapsable-hitarea lastCollapsable-hitarea"></div>
     <span id="top1" class="">top1</span>
     <ul>
       <li class="collapsable lastCollapsable">
         <span class="">mod1</span>
         <ul>
           <li class="last">
              <span>bottom1</span>
           </li>
         </ul>
       </li>
     </ul>
   </li>
   <li class="collapsable lastCollapsable">
     <span id="top2" class="">top2</span>
     <ul>
       <li class="collapsable lastCollapsable">
         <span class="">mid2</span>
           <ul>
             <li class="last">
                <span>bottom2</span>
             </li>
           </ul>
        </li>
      </ul>
    </li>
</ul>

the website allows user to add more data under this structure and am using jquery treeview to show the tree structure dynamically.
Now i need to save this whole ul-li structure into a js object for future use in the website. how do i achieve this? the last node(“bottom1 and bottom2 here”) has a class “last” if that helps.
as we can add data dynamically we can be sure how much levels of ul li is there at the end when user clicks “save”

  • 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-06T05:45:35+00:00Added an answer on June 6, 2026 at 5:45 am

    You can use recursive function to save a tree object;

    function save(obj_ul, tree){
    
        var obj_lis = obj_ul.find("li")
    
        if (obj_lis.length == 0) return;        
    
        obj_lis.each(function(){
            var $this = $(this);
            if($this.parent("ul").get(0) == obj_ul.get(0))
            {
                tree.push({
                    name : $this.find('> span').text(),
                    child : save($this.find("ul").first(), [])
                });
    
    
            }
        });
        return tree;
    }
    
    console.log(save($('#productTree'), []));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following html structure: <div class=divClass> <a class=aClass href=#> <img src=xxxx.jpg <span
Suppose I have the following html: This a test of <code>some code</code>. <div class='highlight'>
I have an HTML along the following lines: <div class=hiddenClass> // this implies display:none
I have the following DOM structure: /*:DOC += <div id='testDiv' class='testDivClass'><div id='innerTestDiv'></div></div><span id='testSpan' class='testSpanClass'><span
I have the following HTML structure, (This cannot change). <!-- Comment 1 --> <div
I have the following (simplified) HTML structure <td> <DIV class=t-numerictextbox> <DIV class=t-formatted-value>$0.00</DIV> <INPUT id=MyObj_PropertyName
I have some HTML with the following approximate structure and positioning: <div class=grand-parent style=position:
I have the following div structure, but this structure is changing <div class=rt-container> <div
I have the following HTML structure,which is a handlebars.js template.: <div class=row id={{serviceId}}> <div
I have the following code: <html> <body> <div style=background-color: lightblue; onClick=alert(myArray[0][1])> this is 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.