07-08-2010

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.

$('input[type=text]').keyup(function(e) {
      if(e.keyCode == 13) {
 	     alert('Enter key detected with  jquery');
      }
});

Or you can use the live method to bind the keyup handler to future additions to the DOM:

$('.someClass').live('keyup',function(e){
	if(e.keyCode == 13) {
		alert('Enter key detected with  jquery');
	}
});

Comments:

Your comment:

»
uiugiouv 06/05/2011, 10:19 am
iugiugbo

 

[x]