Here is the HTML code of the two radio buttons and button
<body>
<input data-image="small" type="radio" id="small" name="size" value="20" class="radios1">
<label for="small"><span></span></label>
<div class="label">Small</div>
<input data-image="green" data-image1="small_green" type="radio" id="green" name="color" value="0" class="radios2" >
<label for="green"><span></span></label>
<div class="label">Green</div>
<button type="button" class="cart-btn" id="cartbutton" name="cart" value="5">Add To Cart!</button>
</body>
Here is the script I have so far. I got it to work with just the radio buttons but when I added the button script it stopped working.
<script>
const sizeSelector = 'input:radio[name=size]';
const colorSelector = 'input:radio[name=color]';
const cartSelector = 'input:button[name=cart]';
$(function () {
// We can add the click event to all radio buttons by linking
// their selectors with commans.
$(`${sizeSelector}, ${colorSelector}, ${cartSelector}`).click(() => {
toggleWhenSmallAndGreenAndCartButton();
});
});
const SMALL = 20;
const GREEN = 0;
const CARTBUTTON = 5;
function toggleWhenSmallAndGreenAndCartButton(){
let size = $(`${sizeSelector}:checked`).val();
let color = $(`${colorSelector}:checked`).val();
let cart = $(`${cartSelector}:selected`).val();
$('#itemdv').toggle(size == SMALL && color == GREEN && cart == CARTBUTTON) && $('#itemdv2').toggle(size == SMALL && color == GREEN && cart == CARTBUTTON);
}
</script>
your button selector is wrong it is not a input type. change it to 'button[name=cart]'