<!-- Code by Fedyaeva -->
<style>
.child__button, .child__button--2, .child__button--3 {
cursor: not-allowed;
}
.child__button a, .child__button--2 a, .child__button--3 a {
cursor: not-allowed;
pointer-events: none;
opacity: 0.5;
}
.child__button.active a, .child__button--2.active a, .child__button--3.active a {
cursor: pointer;
pointer-events: auto;
opacity: 1;
}
.child__button.active, .child__button--2.active, .child__button--3.active {
cursor: pointer;
}
</style>
<script>
window.addEventListener('load', () => {
// Задать кнопкам классы parent__button и child__button
// Для второй и третьих кнопок добавляется порядковый номер в класс --2, --3
let pB = document.querySelectorAll('.parent__button');
let cB = document.querySelectorAll('.child__button');
// Вторая кнопка
let pB2 = document.querySelectorAll('.parent__button--2');
let cB2 = document.querySelectorAll('.child__button--2');
// Третья кнопка
let pB3 = document.querySelectorAll('.parent__button--3');
let cB3 = document.querySelectorAll('.child__button--3');
pB.forEach(e => {
e.addEventListener('click', (evt) => {
cB.forEach(el => el.classList.add('active'));
});
});
pB2.forEach(e => {
e.addEventListener('click', (evt) => {
cB2.forEach(el => el.classList.add('active'));
});
});
pB3.forEach(e => {
e.addEventListener('click', (evt) => {
cB3.forEach(el => el.classList.add('active'));
});
});
function checkProductInCart() {
let productNum = window.tcart.products.length;
if (productNum > 0) {
cB.forEach(el => el.classList.add('active'));
} else {
cB.forEach(el => el.classList.remove('active'));
}
};
checkProductInCart();
});
</script>