Cookies in Phoenix LiveView not taken into account only after the second F5 refresh

But I can alert the value of the cookie.

e.g.

let showTips = Cookies.get(‘showTips’);
alert(showTips);

this code will show the value I have stored in this cookie. This works.

But when I try this:

<div id="user-tips">
    Drink more water and you will feel better.
    <button onclick="hideTips()">Hide tips</button>
</div>

<script>

function hideTips() {
    Cookies.set('showTips', 'false', { expires: 365, path: '' });
    alert(Cookies.get('showTips'))
}

document.addEventListener('DOMContentLoaded', function(event) {
  let showTips = Cookies.get('showTips');
  alert(showTips);

  if (showTips == false) {
    document.getElementById("user-tips").style.display = "none";
  } else {
    document.getElementById("user-tips").style.display = "block";
  }

})

</script>

Only the alert and button click works. So, the library for working with cookies I use is working ok.
So, the cookie is set.

But the if check doesn’t work for some reason. Like it can’t find the id=“user-tips” div or something.