Event Listener

Alternatively you can use the .on() method

The on method receives any valid javascript event name, a callback function and optionaly, a config object

$('.button').on('click',function(e){
//perform action here
});

$('.button').on('mouseleave',function(e){
//perform action here
});

$('.button').on('submit',function(e){
//perform action here
});

$('.button').on('keypress',function(e){
//perform action here
});

//etc...

Still loves addEventListener and onclick, ...?

You can still use them as well.


Last updated