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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:57:12+00:00 2026-05-22T21:57:12+00:00

i have the below structure in HTML, which i use to create a tree

  • 0

i have the below structure in HTML, which i use to create a tree structure using jquery.

<ul>
        <li>Grand Parent
            <ul>
                <li>Parent
                    <ul>
                        <li>child</li></ul>
                </li>
            </ul>
        </li>
    </ul>

every li element has a radio button next to it (not shown in the code, please assume that).

Now if a select value “Child” from the above code then i should get the below result
“Grand Parent > Parent > Child”
and if i select parent then i should get
“Grand Parent > Parent”

So basically the i want to get parent with all its child

Please advise how can i get the above result using jquery

section 1

<ul class='tree js-catTree'><li><a class='expand'></a><span class='treeNodeInner'><input type='radio' name='category'><a id='10209'>Business</a><ul><li><span class='treeNodeInner'><input type='radio' name='category'><a id='10212'>Top</a></span></li><li><span class='treeNodeInner'><input type='radio' name='category'><a id='10214'>New</a></span></li><li><span class='treeNodeInner'><input type='radio' name='category'><a id='10413'>Email and Messaging</a></span></li><li><span class='treeNodeInner'><input type='radio' name='category'><a id='10414'>Finance</a></span></li><li><span class='treeNodeInner'><input type='radio' name='category'><a id='10415'>Mobile Office</a></span></li><li><span class='treeNodeInner'><input type='radio' name='category'><a id='10416'>Sales and Field Force</a></span></li><li><span class='treeNodeInner'><input type='radio' name='category'><a id='10417'>Calculators  Converters</a></span></li><li><span class='treeNodeInner'><input type='radio' name='category'><a id='10418'>Travel  Transportation</a></span></li><li><span class='treeNodeInner'><input type='radio' name='category'><a id='10419'>Reference</a></span></li></ul></span></li><li><a class='expand'></a><span class='treeNodeInner'><input type='radio' name='category'><a id='10962'>asdasd</a><ul><li><a class='expand'></a><span class='treeNodeInner'><input type='radio' name='category'><a id='10964'>asd</a><ul><li><span class='treeNodeInner'><input type='radio' name='category'><a id='10420'>Backup  Optimization</a></span></li></ul></span></li></ul></span></li><li><span class='treeNodeInner'><input type='radio' name='category'><a id='10974'>test_23March</a></span></li></ul>

thanks

  • 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-22T21:57:13+00:00Added an answer on May 22, 2026 at 9:57 pm

    Inside an event handler on the element

    Put this code inside your event handler to get all parents:

    $(this).parents('li').add(this).each(function() {
        // This should iterate through all parent <li>s and the current one too
    });
    

    Try this demo: http://jsfiddle.net/XPL7G/

    Selecting based on a checked radio button

    If you want to select the elements based on which radio button is checked, you can just use the .parents() method.

    Assuming the following HTML markup:

    <ul>
        <li><input type="radio" name="li"> Grand Parent
            <ul>
                <li><input type="radio" name="li"> Parent
                    <ul>
                        <li><input type="radio" name="li"> child</li>
                    </ul>
                </li>
            </ul>
        </li>
    </ul>
    <button>Show me</button>
    

    You can do the following in the button’s click event:

    $('button').click(function() {
        var $obj = $('input[type="radio"]:checked').parents('li');
    
        // The $obj jQuery collection contains your result
    });
    

    Try a demo: http://jsfiddle.net/XPL7G/1/

    Get breadcrumb path as text

    As there are nested elements, we can’t use jQuery’s .text() method, as it would return the combined text from all children as well.

    The solution is to make an array of our jQuery object, reverse the order, then iterate through them, extracting the text node with raw HTML DOM functions as we go (which assuming the same markup as above is the second child of the list item, the first being the radio button).

    $('button').click(function() {
        var $obj = $('input[type="radio"]:checked').parents('li');
    
        var result = '';
        $($obj.get().reverse()).each(function(){
            if(result) result += ' > ';
            result += this.childNodes[1].nodeValue;
        });
    
        // The variable result contains our text breadcrumb
    });
    

    Demo: http://jsfiddle.net/XPL7G/6/

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

Sidebar

Related Questions

I have below table structure in MS SQL AirQuoteID Name SalesValue 7 M 49.50
I have the following model structure below: class Master(models.Model): name = models.CharField(max_length=50) mounting_height =
I have the following bit o' jquery: // Code for Side Navigation $(#sideNav ul
I'm having an issue with the HTML below: <html> <body> <p style=font-size: large> Some
I have the below situation Case 1: Input : X(P)~AK,X(MV)~AK Replace with: AP Output:
I have a grid that will edit small chunks of data based on a
Given a DIV with this general structure (class=post, from an extracted message board post)
I have been struggeling all day to read a json file from server and
I am trying to develop a page to display student/class results by subject/teacher. Some
Ok so I am having a problem with doing multiple forms in rails. here

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.