I am very new to HTML, CSS and JavaScript. I am trying to use jQuery to make a button active or inactive depending on the time of day. I managed to correctly change the image after determining the time ( d ), open time and close time. However, I am having problems assigning a link to buttons based on the time of day.
This code correctly applies the class if the time is between open and close . It also correctly applies the reference to the ButtonOne div only when the ManagersChatButtonActive class is applied, in the JSFiddle. However, in SharePoint it would be, the link also applies even when the time condition is not met.
How can I get a link for use only when the if condition is true?
(This is my first time stack overflow, so I apologize if this is not very well laid out or explained).
$(document).ready(function() { var d = new Date(); var open = new Date(); open.setHours(9); open.setMinutes(0); open.setSeconds(0); var close = new Date(); close.setHours(18); close.setMinutes(0); close.setSeconds(0); if (d >= open && d < close) { $(".ButtonOne").addClass("ManagersChatButtonActive"); $(".ButtonOne").wrap('<a href="http://www.google.com"/>'); } else { $(".ButtonOne").addClass("ManagersChatButtonInactive"); } });
javascript jquery html css sharepoint-2013
Andy gill
source share