Vengat_93 Vengat_93 - 14 days ago 7
jQuery Question

how to create two event for html attribute

I would like to create two event by reusing the code of a method, this is my code, how could i able to create two event for single element using jQuery

$('#country_ID').on({
blur : val (),
submit:val ()
});

function val() {
if ($('#country_ID').val() == '')
{
formval = false;
alert(formval.toString());
}
}


Thanks in Advance..

Answer

The simplest way to do it is as follows:

$('#country_ID').bind('blur submit', function (e) {
    // This is your combined function
    val(); //calling the required function
});