JavaScript Menu Issue
Hello,
I have a very simple question that after looking through the API of jQuery and through this forum, I"m a bit stuck on...
I'm trying to target the second element of a ul based menu.
I have code that works for the first. This basically opens a sub ul menu on page load. I want the second to load on another page.
HTML Example:
noaccordion : no accordion functionality
collapsible : menu works like an accordion but can be fully collapsed
expandfirst : first menu item expanded at page load
<ul id="menu1" class="menu [optional class] [optional class]">
<li><a href="#">Sub menu heading</a>
<ul>
<li><a href="http://site.com/">Link</a></li>
<li><a href="http://site.com/">Link</a></li>
<li><a href="http://site.com/">Link</a></li>
...
...
</ul>
<li><a href="#">Sub menu heading</a>
<ul>
<li><a href="http://site.com/">Link</a></li>
<li><a href="http://site.com/">Link</a></li>
<li><a href="http://site.com/">Link</a></li>
...
...
</ul>
...
...
</ul>
JS
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;
if($(parent).hasClass('noaccordion')) {
$(this).next().slideToggle('normal');
return false;
}
if((checkElement.is('ul')) && ($(this).hasClass("activeLink"))) {
if($(parent).hasClass('collapsible')) {
$("ul:visible", parent).slideUp('normal');
}
$(this).removeClass("activeLink");
return false;
}
if((checkElement.is('ul')) && (!$(this).hasClass("activeLink"))) {
$("ul:visible", parent).slideUp('normal');
checkElement.slideDown('normal');
$("a.activeLink", parent).removeClass("activeLink");
$(this).addClass("activeLink");
return false;
}
if(!(checkElement.is('ul'))) {
check2 = $("a.activeLink", parent).next();
if (check2.is('ul')) {
check2.slideUp('normal');
}
$("ul:visible", parent).slideUp('normal');
$("a.activeLink").removeClass("activeLink");
$(this).addClass("activeLink");
}
}
);
}
$(document).ready(function() {initMenus();});
Thank you so much for your time in advance, its much appreciated.
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Bookmarks