mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-09-02 17:48:50 -04:00
1319 - BUG - adjusting the js to only run when the targeted DOM element exists
This commit is contained in:
@@ -3,22 +3,28 @@
|
|||||||
// Set the target date (10 days before March 15th, 2024)
|
// Set the target date (10 days before March 15th, 2024)
|
||||||
const targetDate = new Date("April 16, 2024 00:00:00").getTime();
|
const targetDate = new Date("April 16, 2024 00:00:00").getTime();
|
||||||
|
|
||||||
|
// Set a const for the container to write a conditional statement and only run if it exists
|
||||||
|
const countdownContainer = document.getElementById("countdown-container");
|
||||||
|
|
||||||
// Function to update the countdown display
|
// Function to update the countdown display
|
||||||
function updateCountdown() {
|
function updateCountdown() {
|
||||||
const now = new Date().getTime();
|
|
||||||
const difference = targetDate - now;
|
|
||||||
|
|
||||||
// Time calculations for days only
|
if (countdownContainer) {
|
||||||
const days = Math.floor(difference / (1000 * 60 * 60 * 24));
|
const now = new Date().getTime();
|
||||||
|
const difference = targetDate - now;
|
||||||
|
|
||||||
// Visibility logic
|
// Time calculations for days only
|
||||||
if (days < 0 || days > 10) {
|
const days = Math.floor(difference / (1000 * 60 * 60 * 24));
|
||||||
// Hide if more than 10 days away OR if already past the date
|
|
||||||
document.getElementById("countdown-container").style.display = "none";
|
// Visibility logic
|
||||||
} else {
|
if (days < 0 || days > 10) {
|
||||||
// Show if 10 days or less remaining
|
// Hide if more than 10 days away OR if already past the date
|
||||||
document.getElementById("countdown-container").style.display = "block";
|
countdownContainer.style.display = "none";
|
||||||
document.getElementById("countdown").innerHTML = days + " days ";
|
} else {
|
||||||
|
// Show if 10 days or less remaining
|
||||||
|
countdownContainer.style.display = "block";
|
||||||
|
document.getElementById("countdown").innerHTML = days + " days ";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user