Streaming live at 10am (PST)

Cookie notice bar - Javascript

Hi all,

I have made a cookie notice bar.
I also added some javascript to disable to cookiebar when a user already accepted, however the cookiebar stays active even when you already accepted.


I’m using the following script. The cookie is being recorded but on page reload the cookiebar still shows.

const cookieContainer = document.querySelector(".cookienoticecontainer");
const cookieButton = document.querySelector(".cookie-btn");

cookieButton.addEventListener("click", () => {
  localStorage.setItem("cookieBannerDisplayed", "true");

setTimeout(() => {
  if (!localStorage.getItem("cookieBannerDisplayed")) {
}, 2000);

Anyone that could help with this?