What I want to happen is when the ".slick-next" button is clicked, the browser waits 3 seconds, and then runs the loadPHP() function. Below is my code, which seems like it theoretically should work, but doesn't. What happens is that the setTimeout function runs once when the page loads, but after that clicking the next button doesn't do anything.
var timeout = null;
$(".slick-next").click(nextButton(timeout));
var nextButton = (function(timeout) {
window.clearTimeout(timeout);
timeout = setTimeout(function() {
loadPHP();
}, 3000);
});
I tried wrapping the whole jQuery expression in a setTimeout, but that doesn't work either. What happens is that you can't click the button for 3 seconds, but then can click it endlessly.
setTimeout(function() {
$(".slick-next").click(nextButton(timeout));
}, 3000));
Why is this behavior happening?