Onblur can be achieved like below:
$().blur()..
But how to catch the event of pressing return while focusing?
Onblur can be achieved like below:
$().blur()..
But how to catch the event of pressing return while focusing?
You look for the character number 13
being pressed. onkeyup
event will be useful.
Question is not so clear. But this might be solution for you...
$("#elm1").blur(function() {
$("#elm").trigger('keyup');
});
ADDED: You might also want to check Events/trigger documentation.
I doubt that what you want is possible, simply because the whole eventing mechanism of jquery (probably because of the browser below it) seems designed to pass you one event at a time. i.e. there is probably a message queue that will get pumped once for each event so that you'll get either the blur or the keypress first but never both.
Even if they were actually scheduled simultaneously on separate threads inside of your browser, I don't think there is a way to work with (let alone inspect the temporary arguments for method calls) from other threads.
This example should work, paraphrased from the jQuery Event docs:
$('input').keyup(function(event){
if (event.keyCode == 13) {
// I'm assuming you want to blur the element?
$(this).blur();
return false; // you may need this, should stop the form submitting
}
});