Jump to content

Display/Hide Buttons on Certain Dates

Recommended Posts

Hi All,
I've found some codes to show/hide buttons {block IDs) on specific dates. I thought I had it all figured out, but they aren't displaying on mobile. Here are the codes I am using...

 

<!-- Enrollment Dates -->
<script>
  $(document).ready(() => {
    // MM - DD - YYYY
  function getDayFromDate(dateString) {
    var now = new Date(dateString);
    var start = new Date(now.getFullYear(), 0, 0);
    var diff = now - start;
    var oneDay = 1000 * 60 * 60 * 24;
    return Math.floor(diff / oneDay);
  }


 let cutoffLow = getDayFromDate("02/26");
  let cutoffHigh = getDayFromDate("03/04");
  let now = getDayFromDate(new Date());

  if(now > cutoffLow && now < cutoffHigh) {
    document.querySelector('#block-yui_3_17_2_1_1696875352874_12959').style.display = "";
  }
  else{
         document.querySelector('#block-yui_3_17_2_1_1696875352874_12959').style.display = "none";
}
});
</script>
 

 

<!-- Waitlist Dates -->
<script>

  $(document).ready(() => {
    // MM - DD - YYYY
  function getDayFromDate(dateString) {
    var now = new Date(dateString);
    var start = new Date(now.getFullYear(), 0, 0);
    var diff = now - start;
    var oneDay = 1000 * 60 * 60 * 24;
    return Math.floor(diff / oneDay);
  }

 let cutoffLow = getDayFromDate("02/05");
  let cutoffHigh = getDayFromDate("02/25");
  let now = getDayFromDate(new Date());

  if(now > cutoffLow && now < cutoffHigh) {
    document.querySelector('#block-yui_3_17_2_1_1706642792709_17177').style.display = "";
  }
  else{
         document.querySelector('#block-yui_3_17_2_1_1706642792709_17177').style.display = "none";
}
});

</script>

Edited by lindz5223
Spelling Error
Link to comment
  • lindz5223 changed the title to Display/Hide Buttons on Certain Dates
  • Replies 1
  • Views 1.2k
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Create an account or sign in to comment

You need to be a member in order to leave a comment

×
×
  • Create New...

Squarespace Webinars

Free online sessions where you’ll learn the basics and refine your Squarespace skills.

Hire a Designer

Stand out online with the help of an experienced designer or developer.