title: jQuery - get the index of <input> throwing a keypress event
body: <p>I'm trying to get the index of an input between a set of inputs. Basically, I have a table that contains, on more than one row, many inputs.</p>
  
  <p>Once the user press the "enter" button, while the input is focused, I need to jump to the next input field, as the "tab" key do.</p>
  
  <p>I was following <a href="https://stackoverflow.com/questions/2335553/jquery-how-to-catch-enter-key-and-change-event-to-tab">this</a> accepted response, and this is what I've done so far: <strong><a href="http://jsfiddle.net/5DwHw/" rel="nofollow noreferrer">Fiddle</a></strong></p>
  
  <p><strong>CODE</strong></p>
  
  <pre><code>$(document).keypress(function(e){
      if( e.which == 13 &amp;&amp; e.target.nodeName == 'INPUT'){
          var inputs = $("#inputsTable input.td_in");
          alert(inputs.index(this));
      }
  });
  </code></pre>
  
  <p>as you can see, every time you focus an input and then press ENTER, the popup msg says "-1"..</p>
  
  <p>What am I doing wrong? I've been struggling with this piece of code for an hour, and I'm giving up.</p>
  
  <hr>
  
  <p>I found out that replacing <code>this</code> with <code>e.target</code> also works.</p>
  
  <p><strong>CODE</strong></p>
  
  <pre><code>$(document).keypress(function(e){
      if( e.which == 13 &amp;&amp; e.target.nodeName == 'INPUT'){
          var inputs = $("#inputsTable input.td_in");
          alert(inputs.index(e.target));
      }
  });
  </code></pre>