Let's assume I want a custom function to handle page transitions. There are event listeners for "click" on both links and div elements on the page. Obviously, in the case of links, I would like to prevent the default link action so that my function can take over redirecting the page after the transition effect is finished.
The jsfiddle below is a simplified example. It works in Chrome, IE, Opera but Firefox throws a ReferenceError: event is not defined
https://jsfiddle.net/hty7tsty/9/
HTML
<div id="div">Div</div>
<a id="link" href="#">Link</a>
<div id="result" style="display:none">Clicked</div>
JS
$('#div, #link').click(myfunc(event));
function myfunc(event){
return function(){
if(event) { event.preventDefault(); }
$('#result').show();
}
}
There are ways for me to avoid the problem, for example, not using <a>
elements, but I would like to understand why Firefox behaves differently.