Discuss and resolve questions on Liquid, JavaScript, themes, sales channels, and site speed enhancements.
In main-product.liquid I have added the following code to display the Variant title in a span tag above the variant pills:
<span class="size-value">
{% assign current_variant = product.selected_or_first_available_variant %}
{{ current_variant.title }}
</span>
How do I update the contents of this span tag when a different Variant pill is selected?
Thanks!
Solved! Go to the solution
This is an accepted solution.
For anyone who has this issue here is the working code to be placed in the onVariantChange() function in global.js:
var checkedValue = document.querySelector('.product-form__input input:checked').value;
document.getElementById("size-value").innerHTML = checkedValue;
Varies wildly by theme and implementations.
You have to edit the themes relevant javascript variant selection functions.
Or add a listener for a the select change event to manipulate the text pulling the title info from the buttons html text.
Contact paull.newton+shopifyforum@gmail.com for the solutions you need
Save time & money ,Ask Questions The Smart Way
Problem Solved? ✔Accept and Like solutions to help future merchants
Answers powered by coffee Thank Paul with a ☕ Coffee for more answers or donate to eff.org
Thanks for the reply, I'm using Dawn 7.0 theme. Any guidance is appreciated!
You don't need to assign span for this you can access by theme javascript in global.js file you can find onVariant change function.
This is an accepted solution.
For anyone who has this issue here is the working code to be placed in the onVariantChange() function in global.js:
var checkedValue = document.querySelector('.product-form__input input:checked').value;
document.getElementById("size-value").innerHTML = checkedValue;
In Canada, payment processors, like those that provide payment processing services t...
By Jacqui Mar 14, 2025Unlock the potential of marketing on your business growth with Shopify Academy's late...
By Shopify Mar 12, 2025Learn how to increase conversion rates in every stage of the customer journey by enroll...
By Shopify Mar 5, 2025