Is there anyway to detect a variant change in Shopify using an external Javascipt/jquery file?

Highlighted
New Member
1 0 0

I have written a external JS script that shows a custom text on the stores product's page. Currently the JS function is called once, on the window.onload function.

I want my script to be able to detect a variant change and swap out the text to a different one, whenever a different variant is selected. How do I detect a variant change and get it's price in an external JS file, using only JS/jQuery function.

 

My code in shopify store:
<script id="testscript" src="https://example.com/test.js?amount=${{ product.price | divided_by: 100.00 | round: 2 }}"></script>
<div id="mydiv"></div>

My code in test.js:
window.onload = function () {
    document.getElementById("mydiv").innerHTML += ("<p>This is a test.</p>");
};
0 Likes
Highlighted
Shopify Expert
1381 111 200

Hi @mahi25,

 

Could you please share your website URL?

0 Likes