Delaying a href Actions Using jQuery
- Article
- Comment
Delaying a href Actions Using jQuery.Some urgent moment, we need to delaying the a href actions. Here i have the code snippet to delay the actions. First we need to stop the action by using the “preventDefault” or Stop Propagation function. As like the following one.
$('a#kvcodes').click(function (e) { // Here mine a href action is triggered e.preventDefault(); // Stop Execution });
Than retrieve the a href url using the following one
var kv_to_url = this.getAttribute("href"); // anchor href url
Now, you can delay the action by using the ” setTimeout” function. The following code snippet will explain you.
setTimeout(function(){ window.location = kv_to_url; },2500);
So, the above codes total compilation, here
$('a#kvcodes').click(function (e) { // Here mine a href action is triggered e.preventDefault(); // Stop Execution var kv_to_url = this.getAttribute("href"); // anchor href url setTimeout(function(){ window.location = kv_to_url; },2500); });
That’s it. if you have any doubt or problem with it comment below, i will help you.