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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T15:59:28+00:00 2026-05-19T15:59:28+00:00

I want all the childs of given node in YUI treeview. Condition is that

  • 0

I want all the childs of given node in YUI treeview. Condition is that if the child has sub-childs then I want sub-sub-child. that is all the childs of given node including subchilds.

I think recursion may be the solution for this problem.Can anyone help me out this.

My current code is

if(curNode.hasChildren()) {
  for(var child = 0; child < curNode.children.length;child++) {
    alert(curNode.children[child].label);
   }
}

By this code, I only get the childrens of given node and not the sub-sub-child nodes.

  • 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-19T15:59:29+00:00Added an answer on May 19, 2026 at 3:59 pm
    var root = $("#root")[0];
    var nodeList = [];
    
    function appendChildren(node, array) {
        if (node.hasChildNodes()) {
            for (var i = 0; i < node.children.length; i++) {
                if (node.children[i].hasChildNodes()) {
                    appendChildren(node.children[i], array);
                    array.push(node.children[i]);
                }
            }
        }
    }
    
    appendChildren(root, nodeList);
    

    Tested here.

    A recursive solution. This can be done more elegantly using functional style programming. This one relies on underscore.js for a cross browser .reduce implementation. You can rely on array.reduce if you target newer browsers.

    function nodeToChildren(node) {
        if (node.hasChildren()) {
            _.reduce(node.children, function (memo, val) {
                return memo.concat(nodeToChildren(val));
            }, [].concat(node));
        } else {
            return node;
        }
    }
    
    var array = nodeToChildren(root);
    

    Give me a few moments to test/debug this.

    I forgot the jQuery option

    var array = $(root).find("*").toArray()

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

Sidebar

Related Questions

I want to iterate over all childs of a jQuery's .children() return value, like
I want to change all child divs(parent div id=product_list) with a width of 41%
I have several child windows, all with the same parent. I want to cascade/tile
I want all products that contain images to be listed before products that do
i have complex XML structure i want get all descendents uisng some xml paren.child.@attribute
I want to give the value of a child node in XML which is
Iam using the following stored procedure for select all child units of the given
given this html <div class=my_div>a</div> <div class=my_div>b</div> <div class=my_div>c</div> <div>other</div> I want select all
Given a Category (parent) and Product (child) tables in a database, say, I want
I have an object-oriented parent-child tree in PHP that I want to clone. The

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.