I have a declared function in my code. I want to call this function whenever I click on an item. When I bind it to this item, it gets executed immediately, and the on click event does not trigger.
However, when I declare the function in the on click binding, it works fine.
I want to declare the function somewhere else first, and then call it when the click event happens
function test2() {
alert('test2');
}
$('body').on('click', '#test1', function() { alert('test1'); });
$('body').on('click', '#test2', test2());