I have a few styling features that use JS throughout my site that I would like to also use within the cart.
So I need the ability to perform some basic Javascript inside Snipcart. Right now any javascript I do in my site’s js file doesn’t work in the cart. As a simple example if I add a div with id “test” in my snipcart template, and then do something like:
document.getElementById("test").innerHTML = "New text!";
it does not work. The text inside the div doesn’t change to "New text!"
.
How can I target elements inside the cart with JS?
I saw this in the docs which I think might have something to with it but not sure how to use it.
document.addEventListener('snipcart.ready', () => {
// You can safely use window.Snipcart here
Snipcart.events.on(...);
});