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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T16:11:17+00:00 2026-05-28T16:11:17+00:00

I have a tree structure like below. when i travese through parent to child

  • 0

I have a tree structure like below.

enter image description here

when i travese through parent to child i want the full path like :
Chemistry->Physical chemistry->Particle theory->Particle theory on clicking the particular node.
and when we go back or click the Physical chemistry then path will return like that :
Chemistry->Physical chemistry

how can we do that.
i am using the following function.

function getParents(id) 
{
  var parents = $("#" + id).parents("ul");
  var selector = "";
  for (var i = parents.length-1; i >= 0; i--) {
    //alert($(parents[i]).find('li').find('span').find('a').html());
    selector += $(parents[i]).find('li').parent().find('span').find('a').html() + " > ";
  }

  //selector += "#" + id;
  $('#breadcrumbs').html(selector);
  //return selector;
}

but it goes to wrong direction.

  • 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-28T16:11:19+00:00Added an answer on May 28, 2026 at 4:11 pm

    This is a prime example for a recursive function.

    function getBreadcrumbs(a) {
        var path = $(a).text(),
            $parent = $(a).parents("li").eq(1).find("a:first");
    
        if ($parent.length == 1) {
            path = getBreadcrumbs($parent) + " > " + path;
        }
        return path;
    }
    
    $("ul a").click(function () {
        $("#breadcrumbs").text( getBreadcrumbs(this) );
    });
    

    See it working over here: http://jsfiddle.net/Tomalak/GFfyg/

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

Sidebar

Related Questions

I have a tree structure in memory that I would like to render in
I have objects in a tree structure, I would like to aggregate status information
I have a very simple binary tree structure, something like: struct nmbintree_s { unsigned
I have a tree structure where each Node has a parent and a Set<Node>
Assuming I have a tree structure UL --LI ---INPUT (checkbox) And I want to
I have a tree-like structure to my database in an app I am writing
I have a simple tree structure represented like this: Node { int Id; int
We have tree structure like this: <Tree> <child1> <child2> <child2> </child1> </Tree> Here the
I have tree structure table like, Table{Id, ParentId, Name} where Id is primary key,
I have a tree-like structure of abstract classes and case classes representing an Abstract

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.