From 11921421db72f8782e42e308a7f86ea2eaadc5a1 Mon Sep 17 00:00:00 2001 From: CodeDevMLH Date: Sat, 21 Dec 2024 02:03:26 +0100 Subject: [PATCH] add div if --- fireworks.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/fireworks.js b/fireworks.js index 18fa9c0..8fdba14 100644 --- a/fireworks.js +++ b/fireworks.js @@ -108,8 +108,13 @@ function createExplosion(x, y) { // Function for the firework with trail function launchFirework() { - const fireworkContainer = document.querySelector('.fireworks'); - if (!fireworkContainer) return; + const fireworkContainer = document.querySelector('.fireworks') || document.createElement("div"); + + if (!document.querySelector('.fireworks')) { + fireworkContainer.className = "fireworks"; + fireworkContainer.setAttribute("aria-hidden", "true"); + document.body.appendChild(fireworkContainer); + } // Random horizontal position const x = Math.random() * window.innerWidth; // Any value across the entire width