Jquery catch only the first keystroke?

I have this code:

$j("#regfname").keypress(function () { alert('Handler for .keypress() called.'); }); 

and want to execute only once ... or just for the first keystroke. What is the best way to do this?

+8
jquery
source share
2 answers

You can use the jQuery one () method to execute only one event per element.

 $j("#regfname").one("keypress", function () { alert('Handler for .keypress() called.'); }); 
+20
source share

You want to use the one function:

 $j('#regfname').one('keypress', function(){...}); 
+6
source share

All Articles