toggle side menu

toggle side menu

hi!

I want to toggle 5 side menus with the same class, but this code doesn't work really good. If I open and close each one after the next, its fine, but if I want to open the next during one is open, i have to click two times. (i know it's because of the variable-counter)

The problem is, that i have no clue if there is a better solution.

Thanks for your support!

  1. $(document).ready(function() {
  2. var number = 0;
  3.  
  4.   $('.side_lash').click(function(){
  5.     if(number == 0){
  6.       $(this).parent('.side_menu').animate({
  7. 'left':'0'
  8. });
  9. $('.side_menu').not($(this).parent('.side_menu')).animate({
  10. 'left':'-222'
  11. });
  12.       number = 1;
  13.     }
  14.     else if(number == 1) {
  15.       $(this).parent('.side_menu').animate({
  16. 'left':'-222'
  17. });
  18.       number = 0;
  19.     }
  20.   });
  21.  });