Show/Hide Based on Date or Time
This allows you to show or hide items based on date or time in Webflow. This is great for event based information, you can display various elements based on if its prior to a time or after a specified time on your Webflow site.
This allows you to show or hide items based on date or time in Webflow. This is great for event based information, you can display various elements based on if its prior to a time or after a specified time on your Webflow site.
How to add it
- Review HTML code for understanding of class names and structure
- Add Javascript to closing body tag of your page custom code
The code
Javascript
<!-- Add to closing body -->
<script>
window.setInterval(function() {
var current = new Date();
var expiry = new Date("Mar 29, 2020 20:21:00")
if (current.getTime() > expiry.getTime()) {
$('.first').hide();
$('.second').show();
} else if (current.getTime() < expiry.getTime()) {
$('.first').show();
$('.second').hide();
}
}, 0);
</script>
HTML
<div class="first" style="display:none">
<p>This will show BEFORE the Expiry time variable</p>
</div>
<div class="second" style="display:none">
<p>This will show AFTER the Expiry time variable</p>
</div>