mardi 6 novembre 2018

IE Failing to evaluate second if condition (&&)

So I have this script:

        function makeActive() {
            var element, name, arr;
            element = document.getElementById("liveChat");
            name = "active";
            arr = element.className.split(" ");
            if (arr.indexOf(name) == -1) {
                element.className += " " + name;
            }
        }

        var currentTime = new Date();
        var currentTimeFormatted = currentTime.toLocaleTimeString();

        if(currentTimeFormatted >= '08:00:00' && currentTimeFormatted <= '16:30:00'){
            makeActive();
        }

Which works perfectly in Chrome, however in IE the class doesn't get added.

If I remove the

&& currentTimeFormatted <= '16:30:00'

IE also adds the class. Why would adding a second condition, break this script within IE?

Aucun commentaire:

Enregistrer un commentaire