I would like to hide the class ".test" if it is past 2:00pm PST on 8/11/2023
const date = new Date();
var timeout = Fri Jun 17 2022 11:27:28 PST+0100;
if (date >= timeout) {
$('.text').hide();
}
I would like to hide the class ".test" if it is past 2:00pm PST on 8/11/2023
const date = new Date();
var timeout = Fri Jun 17 2022 11:27:28 PST+0100;
if (date >= timeout) {
$('.text').hide();
}
2
Answers
timeout
needs to be aDate
object.Your question does not match your code i.e. "if it is past 2:00pm PST on 8/11/2023" since today is 8/1/2023 not 8/11.
But, let’s assume you get the proper date then it is a matter of comparing two dates (as numbers since the epoch ref: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
Get the date parsed properly then you can use the values. Here I use both the
.hide()
and the.toggle(bool)
from jQuery – so with.toggle
we can even avoid the conditional wrap and just hide it with a "false" value. ref: http://api.jquery.com/toggle/#toggle-display