title: Enter triggers button click
body: <p>I have a page with two buttons. One is a <code>&lt;button&gt;</code> element and the other is a <code>&lt;input type="submit"&gt;</code>. The buttons appear on the page in that order. If I'm in a text field anywhere in the form and press <code>&lt;Enter&gt;</code>, the button element's <code>click</code> event is triggered. I assume that's because the button element sits first.</p>
  
  <p>I can't find anything that looks like a reliable way of setting the default button, nor do I necessarily want to at this point. In the absence of anything better, I've captured a keypress anywhere on the form and, if it was the <code>&lt;Enter&gt;</code> key that was pressed, I'm just negating it:</p>
  
  <pre><code>$('form').keypress( function( e ) {
    var code = e.keyCode || e.which;
  
    if( code === 13 ) {
      e.preventDefault();
      return false; 
    }
  })
  </code></pre>
  
  <p>As far as I can tell so far, it seems to be working, but it feels incredibly ham-fisted.</p>
  
  <p>Does anyone know of a more sophisticated technique for doing this?</p>
  
  <p>Similarly, are there any pitfalls to this solution that I'm just not aware of?</p>
  
  <p>Thanks.</p>