Save jQuery callback functions in a separate file
Posted
by Danny Herran
on Stack Overflow
See other posts from Stack Overflow
or by Danny Herran
Published on 2010-06-08T02:55:52Z
Indexed on
2010/06/08
3:02 UTC
Read the original article
Hit count: 286
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?
© Stack Overflow or respective owner