Hide Cookie bar after click on button (javascript)

Hi there,

i have created a cookie bar (div with text and buttons).

I want the cookie bar to hide after a button is clicked (accept or refuse).
For a year, or month…

The cookie bar: [Cookie bar][1]
The html structure: [structure][2]

Cookie bar class: cookie-notice
Cookie bar id: cookie-notice

Accept button class: cn-accept-cookie
Accept button id: cn-accept-cookie

Refuse button: cn-refuse-cookie
Refuse button id: cn-refuse-cookie

How can i do this using javascript (prefer) or jquery?

Thanks alot!

Hi @Elliot_Mersie, you can use something like this.

var accept = document.getElementById('cn-accept-cookie');

accept.addEventListener("click", setCookie();

function setCookie(){
  var d = new Date(); //Get today's date
  d.setTime(d.getTime() + (365 * 24 * 60 * 60 * 1000)); //Set expiry date
  var expires = "expires="+d.toUTCString();//
  document.cookie = "cookieAccept" + "=" + true + ";" + expires + ";path=/";
}

Reference: JavaScript Cookies