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

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="${{ 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>");
Shopify Expert
1336 111 181

Hi @mahi25,


Could you please share your website URL?

Thanks & Regards
Perennial Solution

Problem Solved?✔️Like and Accept the solution that can help others.
Need any help with theme customization or design? Hire us
Skype: infoperennialsolution
PSD to Shopify | Shopify Design Changes | Shopify Custom Theme Development and Desing | Custom Modifications In to Shopify Theme | SEO & Digital Marketing