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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:30:44+00:00 2026-05-27T15:30:44+00:00

I have a tree view. I want the name of the selected node to

  • 0

I have a tree view. I want the name of the selected node to be alerted.
But my code keeps giving me the same name of the node selected for the first time despite of other node selections.

so for example, if I selected Node “A” when I launched the application it will alert “A”.
But if choose something else after that (a different node), it will still alert me with “A”.

Here is the code so far:

 function childnode(event) {
     var treeViewData = window["<%=nav_tree_items.ClientID%>" + "_Data"];
     var selectedNode = document.getElementById(treeViewData.selectedNodeID.value);

     alert(selectedNode.nodeName.toString());             

     return false;
 }

The treeview is generated from a database.

  • 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-27T15:30:45+00:00Added an answer on May 27, 2026 at 3:30 pm

    You have very little context in here, so I am assuming that you want to get the selected node based on some user interaction.

    I suggest using event delegation. This code sets an event handler on your tree dom node, which will handle any click events that happened on a table cell inside it. I am assuming you are using a table. If I am wrong, change the ‘TD’ string to the correct tag name that defines your node.

    When the event handler runs it saves a reference to the active node on the tree node.
    If you want to do something with the active node during a click event, this is where you put your code.
    If you are trying to access the currently selected node from a different scope, use the tree.getSelected() that I also wrote below.

    tree.onclick = function (e) {
        var target = e.target || window.event && window.event.srcElement; // Compatibility code
    
        while (target.tagName !== 'TD') { // Assumes Table cells as the node you are interested in. Replace with other or check className or similar
            target = target.parentNode;
            if (target === this) {
                return; // No relevant node was hit and event bubbled to tree container
            }
        }
    
        this.selected = target;
    
        alert(target);
    };
    
    tree.getSelected = function () {
        return this.selected;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have load a tree view. i want to Traverse treeview node and expand
i have an ASP tree view having a Node so now, i have to
I have an architect question: I want to use Tree View to display some
I have a treeView , and i want to know if some node can
I have a tree view <asp:TreeView ID=TreeView1 runat=server DataSourceID=SiteMapDataSource1 ShowExpandCollapse=False> </asp:TreeView> As you can
I have a tree view defined as follows: <HierarchicalDataTemplate x:Key=ChildTemplate ItemsSource={Binding Children}> <TextBlock Text={Binding
I have a tree view representing certain items. This tree is always two levels
I have a hypothetical tree view that contains this data: RootNode Leaf vein SecondRoot
I have a web application where I am using asp.net tree view control to
I have the same problem as this question , where I want the TreeViewItem

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.