Reputation: 11302
instead of example:
$(".myfield").blur(function() {
// validate
})
$(".myfield").keyup(function() {
// validate
})
is there a way to combine these two?
Upvotes: 20
Views: 13065
Reputation: 507
use with .on() Event
$(document).on("keyup blur", "#myfield", function(event)
{
// your code
});
Upvotes: 4
Reputation: 14205
In case you want to validate each for itself...
$('.myfield').live('blur keyup', function(event) {
if (event.type == 'blur') {
// validate on blur
}
if (event.type == 'keyup') {
// validate on keyup
}
});
Upvotes: 6