title: How can I test whether input has focus in an if structure?
body: <p>I've got this code here now, but the alerts still come up after you click on the input, when it doesn't have focus. I would like to get rid of the click function too, if possible, so that it only alerts when the input has focus.</p>
  
  <pre><code>$('#inputSize').click(function(){
      if ($('#inputSize').is(':focus')){
          $(document).keydown(function(e){
              if (e.keyCode == 38) { 
                 alert( "up pressed" );
                 return false;
              }
                  if (e.keyCode == 40) { 
                 alert( "down pressed" );
                 return false;
              }
          });
      }
  });
  </code></pre>
  
  <p>Thanks!</p>