Event listner on cart doesn't work, dawn theme

Hi everyone. I’m currently use Dawn theme.

I have a bar in announcement-bar.liquid with a message, the message will update when something is added or removed from the cart.

I created this Javascript file

document.addEventListener('DOMContentLoaded', function () {
 console.log("Hi! I'm here!!!");
function reloadAnnouncementBanner() {
 //myCodeHere
});
    }
  }

  document.addEventListener('cart.itemAdded', function (event) {
    console.log("ITEM ADDED");
    reloadAnnouncementBanner();
  });

  document.addEventListener('cart.itemRemoved', function (event) {
    console.log("ITEM REMOVED");
    reloadAnnouncementBanner();
  });
});

From the log i can see the log in the document listner (the “Hi! I’m here” log), so i know i call the js file correctly, but there are no “ITEM ADDED” or “ITEM REMOVED” whenever i try to add or remove an item from the cart, so i think the listner on the cart doesn’t work.

Maybe someone has faced the same issue and has some answer, it’ll be very great!

Thank you very much

Hello,

There must be another functions used for cart items event like add and remove. That’s why your new script on the same event not working. Try to find the flow and add your code in the same function.

Find the function in theme files “product-form.js” or “cart.js”

Let me know.

Hi, sorry for the late reply.

I’ve found the remove function on the cart.js, and it’s working, so really thank you.
On the adding function in product-form.js i’m facing some issues, since i cannot find something clear like the remove function. But i’ll keep searching