0

i want to handling multiple events in one event function. i used jquery ".on" function but it doesn't worked for multiple events. on the following code doesn't work:

$("input.action:checkbox").on('click,change',function(){
    alert('bla bla');
});

When clicked or changed any item on this selector i want fire to the same function. but i dont want to in another function handling. as can be seen following example code i dont want:

    $("input.action:checkbox").on('click',function(){
        changePlease(); // in this func will process 
    });

  $("input.action:checkbox").on('change',function(){
      changePlease(); // in this func will process 
    });

have u got any idea?

Mesuti
  • 878
  • 1
  • 13
  • 29

2 Answers2

4

What you are doing is correct ,but a small syntax issue,Just remove comma between the event names ..

$("input.action:checkbox").on('keyup keypress blur change',function(){
    alert('bla bla');
});

And more possibilities

Community
  • 1
  • 1
Suresh Atta
  • 120,458
  • 37
  • 198
  • 307
1

To answer your question, best way is:

$("input[type=checkbox].action").on('click change',changePlease); 

Just use the name of function as callback, without '()'. BTW, using input[type=checkbox] improve selector performance.

A. Wolff
  • 74,033
  • 9
  • 94
  • 155