I wanted to create a link that would show content before showing a direct link on my forum.
- Show link to download attachment
- After clicking, it shows html content with 5 second countdown below
- When countdown has finished, it shows a direct link.
I have tried the following code:
$("button").click(function() {
$(function() {
var count = 10;
countdown = setInterval(function() {
$("p.countdown").html(count + " seconds remaining!").show("slow");
if (count == 0) {
$("p.new").show("slow");
}
count--;
}, 1000);
});
});
What about a magic function?
To talk about @Bradley Foster’s answer, calling several times
setTimeoutis not reliable.setTimeoutwill stop if your browser lags, so with four differents, you’re not sure the order is going to be the right one. Nesting thesetTimeoutas I’m showing down there is better.Btw, in your question, when you’re doing
$(function() {..., you’re actually doing$(document).ready(function() {.... I guess this is not what you wanted 🙂Jsfiddle here: http://jsfiddle.net/Ralt/kTbcm/