Search code examples
javascriptjqueryfunctionclicklive

Is it possible to combine the 'on' and 'click' jquery functions?


Basically I have code which is follows:

$('selector').on('click',function(){
    //Do something here
});
$('selector').click(function(){
    //Does exact same thing.    
});

Is it possible to combine these? Or would I simply make a function to call from inside both of these bindings?

Apologies if this has been answered, I did check the suggested questions, but didn't find any answers.


Solution

  • $('selector').click() is just a shortcut to $('selector').on('click')