Listen to multiple events in jQuery

2

Is there any simplified way to make a selector listen to various types of events?

Example:

$('meu-seletor').on(['click','touchstart','keyup'],function(){
    // minha ação aqui
});

Currently the only solution I know of would be to create multiple .on() each calling a single event. Is it possible to do it any other way?

    
asked by anonymous 03.11.2014 / 21:49

1 answer

3

Yes, just separate with spaces:

$('meu-seletor').on('click touchstart keyup', function(){
    // minha ação aqui
});

In jQuery documentation says:

  

One or more space-separated event types

    
03.11.2014 / 21:51