title: jquery event only if condition met
body: <p>This is my script:</p>
  
  <pre><code>&lt;script&gt;
  
  if( $('.mydiv').css('display') == 'block'){
      $(".input_a").keyup(function(){
          $(".input_b").val( this.value );
      }); 
  };
  
  $('.mybutton').toggle(
      function(){
          $('.mydiv').css('display','none');
          $(".input_b").val('');
          // now, the event inside the "IF" here above should not occur but it does...
      },
      function(){
          $('.mydiv').css('display','block');
          var f1 = $(".input_a").val();
          $(".input_b").val(f1);
      }        
  );
  
  &lt;/script&gt;
  </code></pre>
  
  <p>What I'm tring to do:</p>
  
  <p>I have to input fields and a div displayed.</p>
  
  <ul>
  <li><p>If the div is shown, I want the input B to be an exact copy of the input A (in real time)</p></li>
  <li><p>if the div is hidden, I want the input B to be cleared and ready to be filled-in.</p></li>
  <li><p>This is where I have a problem: if the div is hidden, typing something in the input A should NOT be mirrored on the input B.</p></li>
  </ul>
  
  <p>This is what my script is about, but the "IF" doesn't seem to work as when the div is hidden, filling in the input B is still mirrored on the input B.</p>
  
  <p>Where am I wrong?</p>
  
  <p>Thank you for your help.</p>