This is a timer. One of the timers is 58 minutes and the other one is 49 hours
The timer was 58 minutes. When the clock reaches 00:00:00, both of them will be as below.
I want to change those that reached the timer 0, what should I do?
It is possible that both of them will reach 0, so I have to make a forEach
.
I want to make it show the end of the discount when it reaches 0.
HTML
<div class="card-footer text-center text-secondary end-discount d-none">End of Discount</div>
<p data-timestamp="1671524779" class="timestamp fw-bolder text-danger text-end mb-0" dir="ltr"></p>
<div class="card-footer text-center text-secondary end-discount d-none">End of Discount</div>
<p data-timestamp="1671524779" class="timestamp fw-bolder text-danger text-end mb-0" dir="ltr"></p>
<div class="card-footer text-center text-secondary end-discount d-none">End of Discount</div>
<p data-timestamp="1671524779" class="timestamp fw-bolder text-danger text-end mb-0" dir="ltr"></p>
<div class="card-footer text-center text-secondary end-discount d-none">End of Discount</div>
<p data-timestamp="1671524779" class="timestamp fw-bolder text-danger text-end mb-0" dir="ltr"></p>
JS
const timestamps = document.querySelectorAll('[data-timestamp]');
timestamps.forEach(function(timestamp) {
setInterval(() => {
const curTime = (new Date()).getTime() / 1000;
timestamp.innerText = (`${timestamp.dataset.timestamp - curTime}`).toHHMMSS();
if (timestamp.innerText === '00 : 00 : 00') {
const end_discounts = document.querySelectorAll('.end-discount');
end_discounts.forEach((end_discount) => {
end_discount.classList.remove('d-none');
end_discount.classList.add('d-block');
});