Show/Hide Content by Time & Date
Contents
About
See additional guides:
This is a variation on the countdown timer which can be used to show or hide large amounts of page content based on a specified date and time. This is ideal for promotions and specials that become available at a certain time, such as a spring sale starting on Sunday at 8am, when someone might not be available to push changes live themselves.
The content is swapped via a script and the usage of two classes: .prepromoContent and .promotionContent. When added to elements or containing <div>s, these classes do the following:
.prepromoContent— displays on page load and is hidden once the timer ends..promotionContent— hidden on page load and is revealed once the timer ends.
Note that this should be treated as a placeholder: once the timer has run out, the page content should be revised as soon as someone is available to clean up the code and leave the new content in place.
If changes need to go live on one date/time, then be reverted at another, all that needs to be done is for the classes .prepromoContent and .promotionContent to be swapped.
Because it is coded with JavaScript as opposed to jQuery, the entire contents of the code can be added to any page block or editable content section by any user role without requiring custom code access.
Display
Below you can see how the countdown block will display before and after the timer runs out.
Main section
This section remains the same.
Lorem ipsum dolor, sit amet consectetur adipisicing elit. Laudantium voluptatem accusamus earum distinctio explicabo corrupti fuga vero, inventore, et optio, delectus nostrum consequatur reiciendis. Dignissimos, facilis. Laborum nisi quo accusamus?
This is going to change.
This content will go away when the timer runs out.
This is the original content.
This will go away soon.
Main section
This section remains the same.
Lorem ipsum dolor, sit amet consectetur adipisicing elit. Laudantium voluptatem accusamus earum distinctio explicabo corrupti fuga vero, inventore, et optio, delectus nostrum consequatur reiciendis. Dignissimos, facilis. Laborum nisi quo accusamus?
This content is here now.
The timer ran out, so here we are.
This is the new content.
It's displaying because the timer ran out.
Demo
Below is an example of how this widget displays. If the content has already updated, click the button to reset the timer.
Time Remaining:
days, hours, minutes, seconds
Time Up
Main section
This section remains the same.
Lorem ipsum dolor, sit amet consectetur adipisicing elit. Laudantium voluptatem accusamus earum distinctio explicabo corrupti fuga vero, inventore, et optio, delectus nostrum consequatur reiciendis. Dignissimos, facilis. Laborum nisi quo accusamus?
This is going to change.
This content will go away when the timer runs out.
This is the original content.
This will go away soon.
Code Snippet
Click below to copy the code snippet to your clipboard.