If you're <div>
containers are arranged accordingly to the menu buttons
you can use the buttons
index to target the corresponding container.
jQuery(function ($) {
var containers = $('.slideDown');
var menuBtns = $('.dropDown');
menuBtns.click(function (event) {
// Prevent the default event.
event.preventDefault();
//get the target container base on the clicked buttons index
var targetContainer = containers.eq($(this).index('.dropDown'));
//show the target container and add class current
targetContainer.slideDown(1100).addClass('current');
//slideUp container that is not the target and remove current class
containers.not(targetContainer).slideUp(1100).removeClass('current');
});
});
See demo here: http://jsfiddle.net/hyTY8/
If you want the container to slideUp
when you click on the same button twice, you can use slideToggle()
instead of slideDown()
. You can also toggle on the class current
using toggleClass()
.
Updated fiddle: http://jsfiddle.net/hyTY8/2/