comebal
comebal

Reputation: 946

How to add multiple event delegation in jquery with focusout

I am trying to execute two events with one "on" function. I have this code:

<input type="text" id="lesson" />

$('#lesson').on("focusout keyup",function(e){
    var $change_education = $(this);
    if(e.which === 188){
       var current_value = $(this).val();
       add_edit_tags(current_value, $change_education);
    }
});

The keyup event is working but the focusout is not. I can't see anything from the web how to solve this.

Thanks

Upvotes: 2

Views: 847

Answers (1)

Arun P Johny
Arun P Johny

Reputation: 388436

The problem seems to be that you are checking for e.which === 188 which will not be set if it is a focusout event, change the condition as below and check

$('#lesson').on("focusout keyup",function(e){
    var $change_education = $(this);
    if(e.type == 'focusout' || e.which === 188){
       var current_value = $change_education.val();
       add_edit_tags(current_value, $change_education);
    }
});

Demo: Fiddle

Upvotes: 1

Related Questions