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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T06:29:05+00:00 2026-05-14T06:29:05+00:00

I have a product database with several product categories. Each category has a number

  • 0

I have a product database with several product categories. Each category has a number of sub-categories, which has sub-sub-categories, which has… Well, quite some levels deep. The tree is too huge to load at once, so I need to built it dynamically as users select specific product categories. Here’s a snapshot of the product tree. Initially, only the first level is loaded. The second level (Cat. 1.1 and cat. 1.2) is added when the user clicks on cat. 1:

<ul id="navigation">
   <li id="625212">Product cat. 1
      <ul>
         <li id="625213">Product cat. 1.1
            <ul></ul>
         </li>
         <li id="625109">Product cat. 1.2
            <ul></ul>
         </li>
      </ul>
   </li>
   <li id="624990">Product cat. 2
      <ul></ul>
   </li>
</ul>

I intend to extend the tree as users click on specific product categories. I can get the list of sub-categories from a URL that takes the parent product category ID as input and outputs HTML in the format needed by treeview. I cannot use PHP and have to make this work with the .click() event. Here’s the code that I have:

$(document).ready(function(){

   function doSomethingWithData(htmldata, id) {
      var branches = $(htmldata).appendTo("#navigation #"+id+" ul");
      $("#navigation").treeview({ add: branches });
   } 

   $("#navigation").treeview({
      collapsed: true,
      unique: true,
      persist: "location"
   });

   $("#navigation li[id]").click(function() {
      var id=$(this).attr("id");
      if ($("#"+$(this).attr("id")+" ul li").size()==0) {
         $.get('someurl?id='+$(this).attr("id"), 
            function(data) { doSomethingWithData(data, id); } )
      }
   }); 

});

The problem I’m having is with the click-event. When clicking on cat 1.1. to extend it one level deeper, it still returns the ID of the top level product category.

How can I change the click events so that it will return the ID of the clicked <LI> instead of the top one?

If the product category does not have any sub-categories, how can I remove the <UL></UL> and thus inidcating that the tree cannot be expanded any further?

  • 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-14T06:29:05+00:00Added an answer on May 14, 2026 at 6:29 am

    To only return one LI, I think you are gonna have to use the code below. This will match only the child of the UL, which is the LI you click on.

    $('#navigation ul > li').click(function() {
          alert($(this).attr('id'));
    });
    

    For removing the UL’s, can you just check if anything gets returned in the $.get? So I guess your click function would look something like this:

    UPDATE – This will select even the top li:

    $('#navigation').click(function(e) {
    
         var element = $(e.target);
         if (element.context.nodeName === 'LI')
         {
           var id = element.attr('id');
           if ($('#' + id + ' ul li').size()==0) 
           {
               $.get('someurl?id='+ id, 
                  function(data) 
                  { 
                    // data could = undefined or something else, just check what 
                    // it looks like when it comes through empty and match that
                    if (data != null) 
                    {
                      doSomethingWithData(data, id);
                    }       
                    else
                    {
                      $('#' + id).children('ul').remove();
                    }
                  }
               );
            }
         }
    
       });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Product Model from the database which I display on the View,
I have several product tables in my database: ProductTypes ProductCategories ProductCategoryItems ProductInventory The way
I have an app with 2 models: Product and Photo , each of which
Each product in my database can have at least three and sometimes four or
I have a database with several tables, 5 of which are dedicated to specific
I currently have several websites which live on separate domains: www.app1.com www.app2.com www.app3.com Each
My product uses a SQL Server database - each client has their own deployed
Current situation: I have a database with following structure: Product Category (contains column product_id)
I have a product database and I am displaying trying to display them as
With our product we have a simple backup tool for the sql server 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.