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');

http://jsfiddle.net/gnrum/941


Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -