|
|||||||
New to SitePoint Forums? Register here for free!
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
SitePoint Enthusiast
![]() Join Date: Apr 2002
Location: chicago
Posts: 72
|
jquery ajax menu collapse expand
Hi I am trying to build something like a tree menu but not exactly. You click a menu, which then does a ajax request for submenus and then displays them. You can then click on the submenus again and get another level of submenus. My problem is sometimes when click on the submenus it does close the menu or sometimes will keep adding to the existing submenu, menaing it will add an identical copy of the submenu, so you see two of the everything. I am using .live to and then is.hidden to see if the menu is visible. Any thoughts as to how I can get this work, toggle can be used with .live as far as I know because you have to click twice?
JavaScript Code:
HTML4Strict Code:
|
|
|
|
|
|
#2 |
|
padawan
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jul 2006
Location: Victoria, Australia
Posts: 2,733
|
I know it doesn't answer your question, but imo this is a really bad use of Ajax, of all elements on a website the main menu should be fast and accessible.
I would suggest loading all the menu content into the page and then just toggling the submenus. |
|
|
|
|
|
#3 |
|
SitePoint Enthusiast
![]() Join Date: Apr 2002
Location: chicago
Posts: 72
|
Thank you for the response and sorry for the confusion. I will try to explain.
The menu is a directory built from a database and there is over 800 items in this menu. It is not the main menu per say but is the main part of the page. To load this all at once into the browser would not be good. I am using ajax to get only parts and then display them as the user browses a category, subcategory and then listing. My question is toggle was not working when I would get json data back from the server. So I then added .live() to attached the new Ajax part of the menu to the Dom. However now I can't reliable toggle the sub menu element using and if else. The sub menu is not part of the initial page load is appended to the page based on what the user clicks on. JavaScript Code:
|
|
|
|
|
|
#4 |
|
padawan
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jul 2006
Location: Victoria, Australia
Posts: 2,733
|
Hi,
I'm not all too familiar with the syntax in your code but here's how I would go about it. The main thing you are missing is to assign the same events that you have setup on page load when you load the new content. I would nest the elements so that the sub content is inside the parent html Code:
javascript Code:
![]() |
|
|
|
![]() |
| Bookmarks |
«
Previous Thread
|
Next Thread
»
| Thread Tools | |
| Display Modes | |
|
|
|
All times are GMT -7. The time now is 19:05.










Linear Mode
