// Получение ссылок на элементы DOM
const contentBlocks = document.querySelectorAll('.content-block');
const addToCartButtons = document.querySelectorAll('.add-to-cart');
// Обработчик события для кнопок "Добавить в корзину"
addToCartButtons.forEach((button) => {
button.addEventListener('click', addToCart);
});
// Функция добавления товара в корзину
function addToCart(event) {
const product = event.target.closest('.content-block');
const productName = product.querySelector('h2').textContent;
const productPrice = product.querySelector('p.price').textContent;
// Здесь можно добавить логику добавления товара в корзину
// Например, отправить данные на сервер или обновить состояние корзины внутри страницы
alert(`Товар "${productName}" добавлен в корзину. Цена: ${productPrice}`);
}
// Дополнительные функции или логика JavaScript могут быть добавлены сюда