## Cookies and JavaScript

JavaScript gives you access to read and write cookies.

This can be used to record when a user dismisses an 'overlay' dialog such as "This site uses cookies", "Sign up for our email list", etc.

JavaScript can set a cookie upon "dismiss", and then only show the overlay dialog if the cookie is not present.

- Cookie Consent with JavaScript Example

    document.addEventListener("DOMContentLoaded",function(){

        /* test if cookie exists for cookie consent
           if it does, hide the consent info overlay */
        /* see:  https://developer.mozilla.org/en-US/docs/Web/API/Document/cookie */
        if (document.cookie.split(';').some((item) => item.trim().startsWith('cookie-consent='))) {
            document.querySelector('#cookieConsent').classList.add('hide');
        }

        /* set up click listener for consent button
            and set cookie and hide consent info */
        document.querySelector('.cookieConsentOK').addEventListener('click',function(){
            console.log("clicked!");
            /* set cookie */
            document.cookie = "cookie-consent=yes";
            /* make overlay disappear */
            document.querySelector('#cookieConsent').classList.add('hide');
        });
      });