OZONE Asylum
Forums
DHTML/Javascript
help with a jquery menu problem
This page's ID:
31006
Search
QuickChanges
Forums
FAQ
Archives
Register
Edit Post
Who can edit a post?
The poster and administrators may edit a post. The poster can only edit it for a short while after the initial post.
Your User Name:
Your Password:
Login Options:
Remember Me On This Computer
Your Text:
Insert Slimies »
Insert UBB Code »
Close
Last Tag
|
All Tags
UBB Help
Hah...yeah, I finally fixed the broken bit that was screwing the whole site up ;) Still haven't done anything else with it though... I have managed to get both parts of my question up and running now, for the record. the original menu code is this: [code] function initMenus() { $('ul.menu ul').hide(); $.each($('ul.menu'), function(){ $('#' + this.id + '.expandfirst ul:first').show(); }); $('ul.menu li a').click( function() { var checkElement = $(this).next(); var parent = this.parentNode.parentNode.id; if($('#' + parent).hasClass('noaccordion')) { $(this).next().slideToggle('normal'); return false; } if((checkElement.is('ul')) && (checkElement.is(':visible'))) { if($('#' + parent).hasClass('collapsible')) { $('#' + parent + ' ul:visible').slideUp('normal'); } return false; } if((checkElement.is('ul')) && (!checkElement.is(':visible'))) { $('#' + parent + ' ul:visible').slideUp('normal'); checkElement.slideDown('normal'); return false; } } ); } $(document).ready(function() {initMenus();}); [/code] I changed it as follows, after Blaise's tips on question 1, and a lot of trial and error with question 2: [code] function initMenus() { $('ul.menu ul').hide(); $.each($('ul.menu'), function(){ $('#' + this.id + '.expandfirst ul:first').show(); }); //start show/hide all attempts................................................... $('#menuhide').click( function(){ $('ul.menu li a').removeClass("menu-active"); $('ul.menu ul').slideUp('normal'); } ); $('#menushow').click( function(){ $('ul.menu li a').addClass("menu-active"); $('ul.menu ul').slideDown('normal'); } ); //end show/hide all attempts................................................... $('ul.menu li a').click( function() { //remove class addition: $('ul.menu li a').removeClass("menu-active"); var checkElement = $(this).next(); var parent = this.parentNode.parentNode.id; if($('#' + parent).hasClass('noaccordion')) { $(this).next().slideToggle('normal'); return false; } if((checkElement.is('ul')) && (checkElement.is(':visible'))) { if($('#' + parent).hasClass('collapsible')) { $('#' + parent + ' ul:visible').slideUp('normal'); } return false; } if((checkElement.is('ul')) && (!checkElement.is(':visible'))) { $('#' + parent + ' ul:visible').slideUp('normal'); checkElement.slideDown('normal'); //add class addition: $(this).toggleClass("menu-active"); return false; } } ); } $(document).ready(function() {initMenus();}); [/code] I am wondering if my show/hide all solution is a good one, or if there something simpler? This works for me, just trying to make sure I am not unnecessarily bloating my code... :) [small](Edited by [url=http://www.ozoneasylum.com/user/163]DL-44[/url] on 05-18-2009 15:25)[/small]
Loading...
Options:
Enable Slimies
Enable Linkwords
« Backwards
—
Onwards »