I am trying to add another announcement bar at our Shopify store below the current announcement bar so that we have 2 stacked on each other but my Javascript wont work. 🙁
I even followed these guidelines to make sure everything was correct.
Link:https://www.askquesty.com/post/how-to-add-javascript-shopify-tutorial
Can anyone help me out?
My code:
<script>
function insertAfter(referenceNode, newNode) {
referenceNode.parentNode.insertBefore(newNode, referenceNode.nextSibling);
}
var el = document.createElement("span.l");
el.innerHTML = "<p class=announcementBar2>FREE SHIPPING</p>";
var div = document.getElementById("announcement-bar");
insertAfter(div, el);
</script>
2
Answers
Ended up using HTML in the header.liquid
Even though this might work, I wouldn’t recommend using JavaScript for this since it may cause layout shifts. I would modify the announcement bar snippet instead, can you provide the GitHub repo with your theme?