I have radio input buttons that I am trying to edit via Google Optimize. There are 2 buttons on the top row and a set of buttons below them linked to the "Delivery Option" button:
I am trying to make it so that when a user clicks the "Delivery Option" button, it remains active while the user toggles between the sub-menu buttons. I'd also like the "Delivery Options" button to go back to the default style once the other main menu button ("One Time Purchase") is selected.
$(document).ready(function(){
$("#radio-subscribe label").on('click', function(){
if($("#attribute_rectangle__136_182 label.active"));
$('#radio-subscribe label').removeClass('active');
$(this).addClass('active');
});
});
When I use this script, I noticed that all of the buttons toggle properly until “One Time Purchase” button is re-selected. Once that happens, the "One Time Purchase" button becomes active, but the "Delivery Option" button stays active as well, even though I want it to go back to the default style
$(document).ready(function(){
$(".df-radio-item label").on('click', function(){
if($("#attribute_rectangle__136_182 label.active"));
$('#radio-subscribe label').removeClass('active');
$(this).addClass('active');
});
});
When I use this script , the top 2 buttons toggle properly, but “Delivery Option” button won’t stay active while bottom row sub-menu buttons are selected
Is there a way to combine the two scripts so that everything works properly? Below is the HTML for reference. Also, sorry if this is a silly question. I'm a complete beginner...
$(document).ready(function(){
$("#radio-subscribe label").on('click', function(){
if($("#attribute_rectangle__136_182 label.active"));
$('#radio-subscribe label').removeClass('active');
$(this).addClass('active');
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="flex delivery-flex">
<div class="option-item df-radio-item" data-label="One-Time Purchase">
<input
data-label="One-Time Purchase"
class="form-radio "
type="radio"
id="attribute_rectangle__136_182"
name="attribute[136]"
value="182"
checked
data-default
>
<label class="form-option" for="attribute_rectangle__136_182" data-product-attribute-value="182">
<span class="form-option-variant">One-Time Purchase</span>
</label>
</div>
<div class="option-item df-radio-item" data-label="Every Week">
<input
data-label="Every Week"
class="form-radio "
type="radio"
id="attribute_rectangle__136_183"
name="attribute[136]"
value="183"
>
<label class="form-option" for="attribute_rectangle__136_183" data-product-attribute-value="183">
<span class="form-option-variant">Every Week</span>
</label>
</div>
<div class="option-item df-radio-item" data-label="Every 2 Weeks">
<input
data-label="Every 2 Weeks"
class="form-radio "
type="radio"
id="attribute_rectangle__136_184"
name="attribute[136]"
value="184"
>
<label class="form-option" for="attribute_rectangle__136_184" data-product-attribute-value="184">
<span class="form-option-variant">Every 2 Weeks</span>
</label>
</div>
<div class="option-item df-radio-item" data-label="Every Month">
<input
data-label="Every Month"
class="form-radio "
type="radio"
id="attribute_rectangle__136_185"
name="attribute[136]"
value="185"
>
<label class="form-option" for="attribute_rectangle__136_185" data-product-attribute-value="185">
<span class="form-option-variant">Every Month</span>
</label>
</div>
<div class="option-item df-radio-item subscribe-grp disabled" data-label="subscribe" id="radio-subscribe">
<input
data-label="Delivery Option"
class="form-radio "
type="radio"
id="attribute_rectangle__136_186"
name="attribute[136]"
value="186"
>
<label class="form-option" for="subscribe_list">
<strong class="form-option-variant">Delivery Option</strong>
<span class="form-option-variant">Save 10% on every shipment in your order</span>
</label>
</div>
