for(let button of cookieBtns){ button.addEventListener('click', function(){ if(this.matches('.accept')){ if(cookieContainer.classList.contains('show')){ cookieContainer.classList.remove('show'); setCookie('site_notice_dismissed', 'true', 30); setCookie('testing', true, 30) } } if(this.matches('.decline')){ if(cookieContainer.classList.contains('show')){ cookieContainer.classList.remove('show'); eraseCookie('site_notice_dismissed'); } } }) } function cookieBtnUpdate() { const cookieBtns = document.querySelectorAll('button[data-cookie="btn"]'); const cookieContainer = document.querySelector('.smp-global-alert'); // functions function setCookie(name,value,days) { var expires = ""; if (days) { var date = new Date(); date.setTime(date.getTime() + (days*24*60*60*1000)); expires = "; expires=" + date.toUTCString(); } document.cookie = name + "=" + (value || "") + expires + "; path=/"; } function eraseCookie(name) { document.cookie = name+'=; Max-Age=-99999999;'; } //event on buttons for(let button of cookieBtns){ button.addEventListener('click', function(){ if(this.matches('.accept')){ console.log(this) } if(this.matches('.decline')){ console.log(this) } }) } } cookieBtnUpdate();
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter