I have several on my website href's, and I need to add a delay between when they are clicked and when they load. Since there are hundreds hrefs, I cannot have a separate js function for each of them.
In two ways that I explored, the contents of href were passed to javascript as a variable, for example:
<a href="example1.php">example1</a>
<a href="example2.php">example2</a>
<a href="example3.php">example3</a>
<script>
var href =
$(function() {
$("a").on("click", function(event) {
event.preventDefault();
setTimeout(function(){window.location.href = href;}, 1000);
});
});
Can this be done using CSS?
source
share