I have a text field that I need only to display for a certain period of time. I need it to appear after 5pm and stop appearing at 7am daily. The piece of text has been saved as a variable.
How do I do this? Thanks
I have a text field that I need only to display for a certain period of time. I need it to appear after 5pm and stop appearing at 7am daily. The piece of text has been saved as a variable.
How do I do this? Thanks
You can get time using Date() object and then show and hide your text. e.g
HTML:
<div class="someClass">Your text </div>
JavaScript:
var currentDate = new Date();
var currentTime = currentDate.getHours();
if(currentTime >=17 || currentTime <=7) {
document.getElementsByClassName('someClass')[0].style.visibility = 'visible';
} else {
document.getElementsByClassName('someClass')[0].style.visibility = 'hidden';
}