I have an input field and a login button. I want to allow users to hit the \"enter\" key to click the button when the input field is focused. How would I do this with jQuery?<
If they're in the same form and you change the button to be type="submit" you should find it happens automatically, but anyway...
type="submit"
$(document).ready(function() { $('#loginUserID').keypress(function(e){ if(e.which === 13) $('#loginBtn').click(); }); });
(Or you may prefer .keyup or .keydown.)
.keyup
.keydown