Cannot read properties of null for cookie consent

I’m trying to set a cookie notice on my site. Above code is giving me error: Cannot read properties of null.

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

     if (document.cookie.indexOf('accepted-cookie') == -1) {
         document.cookie='cookie_name=VALUE; path=/';
         ShowStuff('cookie-notice');
     }  else {
        document.cookie='cookie_name=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/';
        HideStuff('cookie-notice');
     }
}, false);

function ShowStuff(id) {
    if (document.getElementById(id).style.display == 'none')
    {
        document.getElementById(id).style.display = 'block';
        document.cookie='cookie_name=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/';
    }
}

function HideStuff(id) {
    if (document.getElementById(id).style.display != 'none')
    {
        document.getElementById(id).style.display = 'none';
        document.cookie='cookie_name=VALUE; path=/';
    }
}

How can I fix this error?