How close does preventdefault() have to be to the source event?
consider the following code
- var tempEvent;
- $('a').on('click',function( e ){
- e.preventdefault()
- tempEvent = e;
- someOtherFunction()
- });
- function someOtherFunction(){
- tempEvent.preventdefault()
- }
In this example there are two preventdefault() statements
The first (green) one works
The second (red) one does not (even if you remove the first)
Why is this?
is it anything to do with the fact that the event has been stored in a global scope variable?
would it make any difference if the event was passed to the second function as an argument?
when is the latest point at which you can preventdefault()