let's say I have a link:
<a href='http://example.com/file.zip' id='dl'>Download</a>
And while someone click on it, I want to do something, such as:
$("#dl").live("click", function(e){
e.preventDefault();
$("#dlbox").fadeOut(500);
});
Is there a way after I e.preventDefault, to go ahead and doDefault? something like
$("#dl").live("click", function(e){
e.preventDefault();
$("#dlbox").fadeOut(500);
e.doDefault();
});
so it'll run the event normally?
There is no opposite method of event. preventDefault() to understand why you first have to look into what event. preventDefault() does when you call it. Underneath the hood, the functionality for preventDefault is essentially calling a return false which halts any further execution.
The preventDefault() method is used to prevent the browser from executing the default action of the selected element. It can prevent the user from processing the request by clicking the link. Parameters: It does not accept any parameter.
In a web page, you should call the preventDefault() method of the event if you have accepted the drop, so that the browser's default handling is not triggered by the dropped data as well. For example, when a link is dragged to a web page, Firefox will open the link.
preventDefault() prevents the default browser behavior for a given element. stopPropagation() stops an event from bubbling or propagating up the DOM tree. Whereas, return false is a combination of both preventDefault() and stopPropagation() .
You can only prevent the default behavior (with e.preventDefault()
).
Now if you expect the link to be navigated when the .fadeOut() method has finished, you should prevent the default behavior and use the callback parameter of the fadeOut method to navigate when the animation has finished:
$("#dl").live("click", function(e){
e.preventDefault();
var href = this.href;
$("#dlbox").fadeOut(500, function() {
window.location = href;
});
});
DEMO
There is no doDefault() command, you need to re-architect your code.
I would prevent default, then perform the url direct yourself via window.location
. Possibly use a different tag to an anchor tag too - by overriding its functionality it makes no sense to use it in the first place.
eg something like this:
$("#dl").live("click", function(e){
e.preventDefault();
$("#dlbox").fadeOut(500, function() { window.location='www.fish.com'; });
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With