Is there any way in jquery to change the contents of a div based on timer.
Assume i have module to give "tips". The contents of the tips should change every 5 seconds.
Thanks
Make an array of tips. Then make a interval
of 5 seconds that change the div's content. I assume you want random tips.
See this example on jsFiddle.
var tips = [
"Tip 01",
"Tip 02",
"Tip 03",
"Tip 04",
"Tip 05",
"Tip 06",
"Tip 07",
"Tip 08",
"Tip 09"
];
// get a random index, get the value from array and
// change the div content
setInterval(function() {
var i = Math.round((Math.random()) * tips.length);
if (i == tips.length) --i;
$("#tip").html(tips[i]);
}, 5 * 1000);
See:
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