I have one text box when user enter in text box and hit enter it should alert the value, and also if user change the value it should also alert. So there will be two events keypress and change. And I want call this with minimum code. no duplicate codes.
$('#txt').keydown(function (e){
if(e.keyCode == 13){
alert('you pressed enter ^_^');
}
})
You can list multiple events as the first parameter (though you still have to handle each event):
I’m using bind on purpose, because the OTs fiddle uses jQ 1.5.2