0
<div class="col-12 first-div">
</div>

<div class="col-12 second-div">
</div>

How do I set up to change the class on a FIRST DIV at a specific time, with jQuery or javascript .

I want the FIRST DIV to be visible until a certain date and time, then for it to become a DISPLAY:NONE and for the SECOND DIV to become visible at that time, and to restart the page once.

Gavrilo011
  • 1
  • 1
  • 1

2 Answers2

2

I think you can use a setInterval() to check the time every second , and if the time is between your specified times , show and hide the divs



function refreshTime() {
    const now = new Date().getHours()
    if (now >= 9 && now <= 18) { //show the first div from 9 am to 6 pm
        document.getElementById('first-div').style.display ='block';
        document.getElementById('second-div').style.display ='none';  // to display
} else {
       document.getElementById('second- div').style.display ='block';
        document.getElementById('first-div').style.display ='none';  // to display
 }
}
 setInterval(refreshTime, 1000);

replace the 1000 inside the setInterval to anyother number if you dont want to recheck the time every one second ,

Akash NO
  • 308
  • 3
  • 11
  • Thanks for the help, I need to be able to set in this format: newDate ('05/31/2022 07:00:00 PM ') I have to be able to set at any time eg 00:00 AM, or 03: 50PM. I also need to refresh the page window.location.reload (); but so do it only once. So I have to somehow remember that First DIV has an Activ class, or that the display: block. While the other DIV does not have an Activ class, or has a display:none. In JS I have to be able to set any time (day, month, year, hours, minutes) – Gavrilo011 May 31 '22 at 17:10
-1

I fail to refresh the page with this only once.I fail to refresh the page with this only once.

Gavrilo011
  • 1
  • 1
  • 1