title: Intercept keypress and change focus in jQuery
body: <p>I have a list of <code>div.boxinput</code> (each with two input fields). If a key like down arrow is pressed, I need to change focus of other input.</p>
  
  <p>I can intercept the key, but I cannot move the focus to another input.</p>
  
  <pre><code> $(document).keydown(function(e) {
         e.preventDefault();
         if (e.keyCode == 40) { 
           alert("down"); 
  
            // find where is the focus ? 
             var hasFocus = $('input').is(':focus');
             alert(hasFocus);
  
  
           // change focus ( problem here, don't change focus )
           if ( $(hasFocus).parent().hasClass("reso") ) {
               $(hasFocus).parent().prev().find("input").focus();
            }else{
               $(hasFocus).parent().next().find("input").focus();
            }
  
        }     
  
         if (e.keyCode == 37) { alert("left"); }
         if (e.keyCode == 38) { alert("top"); }
         if (e.keyCode == 39) { alert("right"); }
  });
  </code></pre>
  
  <p>I create my experiment here: <a href="http://jsfiddle.net/andreaferri/mt95g9cu/7/" rel="nofollow">jsfiddle.net/andreaferri/mt95g9cu/7/</a></p>
  
  <p>How do I select the item that has focus?</p>