I need to convert via jquery, on page load, a text time shown as a <span class="countdown-timer">Nov-07-2021 08:34:00 EST</span>
into a timer. On same page there are various times, not just that specific timer so the script should run all the classes .countdown-timer and show the proper countdown, based on the time that each have.
The code that i am using works just for minutes and also it seems to start over instead of stopping or showing ideal, a ENDED message instead of the countdown.
var interval = setInterval(function() {
var timer = $('span').html();
timer = timer.split(':');
var minutes = parseInt(timer[0], 10);
var seconds = parseInt(timer[1], 10);
seconds -= 1;
if (minutes < 0) return clearInterval(interval);
if (minutes < 10 && minutes.length != 2) minutes = '0' + minutes;
if (seconds < 0 && minutes != 0) {
minutes -= 1;
seconds = 59;
}
else if (seconds < 10 && length.seconds != 2) seconds = '0' + seconds;
$('span').html(minutes + ':' + seconds);
if (minutes == 0 && seconds == 0)
clearInterval(interval);
}, 1000);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<span>Nov-07-2021 08:34:00 EST</span>