Set a cookie on interaction

i wanted to share a script to set a cookie, so an interaction would show only when cookie criteria is met, e.g: once a day/week etc… (you can change it as you see fit). i’m using js-cookie lib for that.

<script src=""></script>
document.addEventListener("DOMContentLoaded", function(event) { 
  // get a reference to the loading wrapper
  const popUp = document.querySelector('CLASS-NAME-OF-THE-ELEMENT-U-ANIMATE');

  // get the 'seenAnimation' cookie and store in a seenAnimation variable
  const seenAnimation = Cookies.get('seenAnimation');
  // if the 'seenAnimation' cookie is undefined
    // set the 'seenAnimation' cookie 
    Cookies.set('seenAnimation', 1, { expires: 1 });
    // else if the 'seenAnimation' cookie exists
    // the user has already seen the animation
    // and so
    // hide the loading-wrapper = "none"; = "0";

in this script i’m hiding the loading wrapper if cookie exist by applying these styles: = “none”; = “0”;


Thanks very much for that - saved some messing about :slight_smile:

I used document.getElementById for getting the div to hide.

Thanks for sharing! Can be quite useful!

GOODNESS!! Best one yet.

I have tried a few and this one actually works like magic!!!