December 16, 2022
The following code expects your toggled element to have an ID of "my-element", but can be changed to whatever you want.
The openingHour and closingHour variables are set to 8 and 17 respectively, translating to opening hours between 8 AM and 5 PM.
The GMT variable is currently set to 2, which translates to the timezone in Finland (amongst others) GMT+2. Change the value of this variable to your local GMT timezone.
$(document).ready(function () {
let openingHour = 8;
let closingHour = 17;
let GMT = 2;
let time = new Date();
// Convert the time to the local timezone
time.setTime(time.getTime() + GMT * 60 * 60 * 1000);
if (time.getHours() >= openingHour && time.getHours() < closingHour) {
$("#my-element").show();
} else {
$("#my-element").hide();
}
});