Two click functions where the second one is requiring an additional click to fire.

Two click functions where the second one is requiring an additional click to fire.

hello everyone,

I can not seem to understand why when the second div is clicked it is needing to be clicked a second time in order to run. Any help is greatly appreciated!

  1. $(document).ready(function(){

  2. var $moveOne = $('#three'),
  3.         $moveTwo = $('#two');
  4.   
  5.     var   r = 0, 
  6.         dir = true;

  7.  

  8.    $('.enable2').unbind().click(function(e) {
  9.      if (e.target !==this)
  10.        return;
  11. console.log('clicked');
  12.        dir = !dir;
  13.        r = dir? -625 : 0;
  14.        $moveOne.stop().animate({right: r+'px'}, 400);
  15.        
  16.    });
  17.   $('.enable1').unbind().click(function(f) {
  18.     if (f.target !==this)
  19.        return;
  20.    console.log('clicked');
  21.        dir = !dir;
  22.        r = dir? -625 : 0;
  23.        $moveTwo.stop().animate({right: r+'px'}, 400);
  24.        
  25.    });
  26. });