All things Shopify and commerce
Need to show a div for custom size button only when the Option "Custom" is selected but whenever I use Product.option with if condition it just completely blocks the div from showing on the product page.
Kindly guide how to solve
<!-- Example HTML structure -->
<select id="product-options">
<option value="standard">Standard</option>
<option value="custom">Custom</option>
</select>
<div id="custom-size-div" style="display: none;">
<!-- Your custom size button and related content -->
<button>Custom Size Button</button>
</div>
<script>
// Get a reference to the select element
const selectElement = document.getElementById('product-options');
// Get a reference to the div you want to show/hide
const customSizeDiv = document.getElementById('custom-size-div');
// Function to handle showing/hiding the custom size div
function toggleCustomSizeDiv() {
if (selectElement.value === 'custom') {
customSizeDiv.style.display = 'block';
} else {
customSizeDiv.style.display = 'none';
}
}
// Attach event listener to detect changes in select element
selectElement.addEventListener('change', toggleCustomSizeDiv);
// Initial check on page load
toggleCustomSizeDiv();
</script>
Discover how to increase customer engagement on your store with articles from Shopify A...
By Jacqui Apr 23, 2025Hey Community 👋 Did you know that March 15th is National Everything You Think Is W...
By JasonH Apr 1, 2025Discover how to increase the efficiency of commerce operations with Shopify Academy's l...
By Jacqui Mar 26, 2025