Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

163
Views
Local storage function call preventing other function from working

Hi i have a project whereby onclick of a griD advent windows show. I want to save the ones opened from the previous session. I'm using local storage saving the HTML div (child of container class). When I invoke the function it stops the other windows from opening. All HTML within the container is generated by JS.

const calendarContainer = document.querySelector(".container");
const calendarDays = 24;
const d = new Date();
const todaysDate = d.getDate();
const todaysDatePlusOne = todaysDate + 1;


const openDoor = (path, event) => {
  const dayClicked = event.target.innerHTML;

  if (dayClicked < todaysDatePlusOne) {
    event.target.parentNode.style.backgroundImage = `url(${path})`; //binds calendar door click listener
    event.target.style.opacity = "0";
    event.target.style.backgroundColor = "#521751";
  } else {
    //modal pop up with Giff
    const modal = document.getElementById("myModal");
    modal.style.display = "block";
    setTimeout(function() {
      modal.style.display = "none";
    }, 2250);
    return;
  }
  let calendarHTML = calendarContainer.innerHTML;
  // Save the HTML to localStorage to keep doors open on next 
  session
  localStorage.setItem("doorsOpenedPreviously", calendarHTML);
};

const createCalendar = () => {
  for (let i = 0; i < calendarDays; i++) {
    const calendarDoor = document.createElement("div");
    const calendarDoorText = document.createElement("div");

    calendarDoor.classList.add("image");
    calendarDoor.style.gridArea = "door" + (i + 1);
    calendarContainer.appendChild(calendarDoor);

    calendarDoorText.classList.add("text");
    calendarDoorText.innerHTML = i + 1;
    calendarDoor.appendChild(calendarDoorText);

    adventWindowNumber = i + 1;
    let adventPath = `/Images/xmas-images/xmas-${adventWindowNumber}.jpg`;

    calendarDoorText.addEventListener("click", openDoor.bind(null,
      adventPath));
  }
};

const loadPreviousOpenedDoor = () => {
  // Check for saved wishlist items
  let saved = localStorage.getItem("doorsOpenedPreviously");
  calendarContainer.innerHTML = saved;
};

createCalendar();
loadPreviousOpenedDoor();
<h1>Xmas Advent Calendar 2021</h1>
<div class="container"></div>

<div id="myModal" class="modal">
  <div class="modal-content">
    <span class="close">&times;</span>
    <p>Too early Heidi!!</p>
    <iframe src="https://giphy.com/embed/LIhO05Vq0d9XqDg2tw" width="480" height="269" frameborder="0" class="giphy-embed" allowfullscreen></iframe>
  </div>
</div>

<script src="app.js"></script>

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!