html - Issue with jQuery countdown timer -
i'm working timers when click button timer starts 5 seconds , fadesout when comes 0. tried couldnt , here fiddle i've tried: http://jsfiddle.net/gnrum/937/
<div id="hidemsg" style="display:none;"> box close in <span>5</span> seconds..</div> <input id="take" type="button" value="click me" >
jquery code :
$("#take").live("click", function () { $('#hidemsg').show(); var sec = $('#hidemsg span').text() var timer = setinterval(function () { $('#hidemsg span').text(--sec); if (sec == 0) { $('#hidemsg').fadeout('fast'); clearinterval(timer); } }, 1000); });
it's working first click, when click 2 time count starts 0,-1,-2,. not clear intervals. help?
try re-initialize $('#hidemsg span')
. $('#hidemsg span').text('5');
Comments
Post a Comment