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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T00:55:37+00:00 2026-05-18T00:55:37+00:00

Im trying to show a jQuery menu that is built from and ajax call

  • 0

Im trying to show a jQuery menu that is built from and ajax call to a xml file and then an event handler is attached to all the li objects that has submenus. My problem is that it dosnt work. If I press a subcategory that should expand and show a submenu, this is done but the top node in my tree also cahnges its hide/show value? So something is wrong with my event bind, please help me!

    function heightToggle(showhide) {       
    $(this).children("ul").is(":hidden") ? $(this).children("ul").show() : $(this).children("ul").hide();
}

function createNode(parent)
{    
    var current = $("<li/>").attr("id", $(this).attr("ID") || "").html("<span>"+ $(this).attr("name") +"</span>").appendTo(parent);

    if($(this).children("node").length != 0)
    {
        var branch = $("<ul/>").appendTo(current);
        current.addClass("hasChildren");            

        branch.hide();
        var findElem = $("#" + $(this).attr("ID"));
        findElem.bind('click', heightToggle);

        $.each($(this).children("node"), createNode, [branch]);                    

    }
}

var domain = "<%=domainId %>";
var nodeId = "<%=nodeId %>";
var path = "<%=path %>";

var container = $("#menuContainer");

$.ajax({
  type: "POST",
  contentType: "application/x-www-form-urlencoded",
  url: "../webservices/productNavXml.asmx/GetXmlNodes",
  data : "companyId=" + domain,
  dataType: "xml",
  success: function(xml) {
    $.each($(xml).find("node[name='Products']").children("node"), createNode, [container]);        
    }
});      



  if(nodeId != null && nodeId != "")
  {
    GetProductPage(nodeId);
  }

});


menu looks like this if not expanded

1.TopMenu
1.1 sub
1.2 sub
2.TopMenu

if I press 1.1 im supposed to get a third lvl 1.1.1 but instead “1.TopMenu” closes to that all i see is

1.TopMenu
2.TopMenu

Please do help!

Best Regards
Marthin

  • 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-18T00:55:38+00:00Added an answer on May 18, 2026 at 12:55 am

    So i found my problem. I tried to add an eventhandler to each li-tag. When I whent down the tree i did not only click on the current li but also its parent li, so more then one call where made to heightToggle function. The total calls where one + one for each li-parent.
    I solved this by adding event handler to the span-tag insted of the li object.

    function createNode(parent)
    

    {
    var current = $(“”).attr(“id”, $(this).attr(“ID”) || “”).html(“”+ $(this).attr(“name”) +””).appendTo(parent);

    if($(this).children("node").length != 0)
    {
        var branch = $("<ul/>").appendTo(current);
        current.addClass("hasChildren");            
    
        branch.hide();
        var findElem = $("#" + $(this).attr("ID"));
        findElem.bind('click', heightToggle);
    
        $.each($(this).children("node"), createNode, [branch]);                    
    
    }
    

    }

    I change to this insted

    function createNode(parent)
    {    
        var current = $("<li/>").attr("id", $(this).attr("ID") || "").appendTo(parent);
        var textSpan = $("<span/>").html($(this).attr("name")).appendTo(current);
        if($(this).children("node").length != 0)
        {
            var branch = $("<ul/>").appendTo(current);
            current.addClass("hasChildren"); 
            branch.hide();  
            $.each($(this).children("node"), createNode, [branch]);  
        }
        textSpan.click(heightToggle);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to learn some things from AJAX and jQuery, i believe that
I'm new to jQuery. I have an accordion menu that I am trying to
I am trying to jazz up my .show() jquery function so that the previously
I am trying to use jQuery to show a div when the user selects
I'm trying to show/hide a movieclip (or graphic) symbol that is on a layer
I am very new to javascript and ajax/jquery and have been working on trying
I am trying to use jquery to show my div containers coordinate with my
Trying to make a simple toggle menu, and I can't seem to hide/show the
having murders with this jQuery. I am trying to show a set of db
I'm trying to build a jquery dropdown menu, basically I have the left navigation

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.