What is a better way to implement this toggle class using JS?
What this is doing is simply this:
When you click either "Services", "Gallery", or "Customer", it removes the class "hidden" in the div below, and adds the class "hidden" to all other lists within the same div.
A live demo of what is happening can be seen here: http://www.cyberbytesdesign.com/WIP2 (it's the main header navigation).
Here is the code that I am using (definitely not an efficient way as this is less than half of all the code, but gets the point across).
<nav>
<ul class="menu-option-set">
<li>
<a href="javascript:;" onmouseup="
document.getElementById('services').classList.toggle('hidden');
document.getElementById('gallery').classList.add('hidden');
document.getElementById('customer').classList.add('hidden');
">Services</a>
</li>
<li>
<a href="javascript:;" onmouseup="
document.getElementById('gallery').classList.toggle('hidden');
document.getElementById('services').classList.add('hidden');
document.getElementById('customer').classList.add('hidden'); ">Gallery</a>
</li>
<li>
<a href="javascript:;" onmouseup="
document.getElementById('gallery').classList.toggle('hidden');
document.getElementById('services').classList.add('hidden');
document.getElementById('customer').classList.add('hidden'); ">Customer</a>
</li>
</ul>
</nav>
<div id="header-subnav">
<nav>
<ul id="services" class="hidden">
<li <?php echo $bathroom ?>><a href="bathroom">Bathroom</a></li>
<li <?php echo $kitchen ?>><a href="index.php">Kitchen</a></li>
<li <?php echo $accessibility ?>><a href="index.php">Accessibility</a></li>
</ul>
<ul id="gallery" class="hidden">
<li <?php echo $photo ?>><a href="gallery.php">Photo Gallery</a></li>
<li <?php echo $project ?>><a href="project.php">Project Gallery</a></li>
</ul>
<ul id="customer" class="hidden">
<li <?php echo $coupons ?>><a href="coupons.php">Coupons</a></li>
<li <?php echo $testimonials ?>><a href="testimonials.php">Testimonials</a></li>
</ul>
<nav>
</div>
I'm assuming that you have to do something similar to using this somehow, but modified:
$('.menu-option-set a').click(function()
{
// if clicked item is selected then deselect it
if ($('#header-subnav').hasClass('hidden'))
{
$('#header-subnav').removeClass('hidden');
}
// otherwise deselect all and select just this one
else
{
$('.menu-option-set a').removeClass('hidden');
$('#header-subnav').addClass('hidden');
}
});
Any ideas?