jQuery - detect enter key in jQuery
the following line of jQuery let's you detect when an enter key was pressed while focus was on a text input element.
Or you can use the live method to bind the keyup handler to future additions to the DOM:
$('input[type=text]').keyup(function(e) { if(e.keyCode == 13) { alert('Enter key detected with jquery'); } });
$('.someClass').live('keyup',function(e){ if(e.keyCode == 13) { alert('Enter key detected with jquery'); } });
Since the live method has been is deprecated in jQuery, nowadays the second example would be written something like this:
iugiugbo