Probably I missed something, but lets say I have this:
$('a.delete').click(function(){
resp=window.confirm("Are you sure you want to delete this?");
if(resp)
return true;
else
return false;
}
Now, I want to save that callback function into a separate js file, because I will use it in several pages. My logic told me to do this:
$('a.del').click(delete_element());
Having my js file like this:
function delete_element(){
resp=window.confirm("Are you sure you want to delete this?");
if(resp)
return true;
else
return false;
}
This doesn't work. Everytime my page loads, it displays the confirm window, even if I haven't clicked the link.
It is clear that my logic failed this time. What am I missing?