src
у button
нужно переименовать в data-src
, чтобы получать его через dataset
.document.addEventListener('click', switchColorButtonHandler);
function switchColorButtonHandler({ target }) {
const clickedButton = target.closest('.slide-product__options');
if (!clickedButton) return;
const productWrapper = clickedButton.closest('.slide-product__image');
const productImage = productWrapper.querySelector('.picture img');
productWrapper.querySelectorAll('button').forEach(button => {
button.classList.remove('_active');
});
clickedButton.classList.add('_active');
productImage.src = clickedButton.dataset.src;
}
const salaryFilter = document.querySelector('.third__filter-item');
const salaryFilterFrom = salaryFilter.querySelector('.third__filter-from');
const salaryFilterTo = salaryFilter.querySelector('.third__filter-to');
const cvBlocks = document.querySelectorAll('.watch__anceta');
salaryFilter.addEventListener('input', filterBySalary);
function filterBySalary() {
cvBlocks.forEach(cvBlock => {
const salary = +cvBlock.querySelector('.watch__price').textContent.match(/\d+/);
const isInRange = salary >= +salaryFilterFrom.value && salary <= +salaryFilterTo.value;
cvBlock.classList.toggle('hide', !isInRange);
})
}
function renderItem(cardData) {
const newCard = cardTemplate.cloneNode(true);
const cardTitle = newCard.querySelector('.card__title');
const cardImage = newCard.querySelector('.card__image');
cardImage.src = cardData.link;
cardTitle.textContent = cardData.name;
container.append(newCard);
}
renderItem(); //← поэтому семь
render();
cardRecommended.forEach((card) => {
card.addEventListener('click', (e) => {
if (popupRecommended.classList.contains('-open') || e.target.classList.contains('favorite-btn')) return;
popupRecommended.classList.add('-open');
document.body.classList.add('-lock');
})
})
const accordTitles = document.querySelectorAll('.elem-top');
accordTitles.forEach(title => {
title.addEventListener('click', textdown)
})
function textdown({currentTarget}) {
currentTarget.nextElementSibling.classList.toggle('active_text');
currentTarget.querySelector('.faq__arrow').classList.toggle('arrow_rotate');
};
<div id="pdf-links"></div>
<div id="control-buttons">
<button>Кнопка 1</button>
<button>Сборосить</button>
</div>
const arr = [{id: 25-1, title: 'GA-1200 8MM', pdf: 'ссылка.pdf'},
{id: 25-2, title: 'GA-1232 9MM', pdf: 'ссылка.pdf'},
{id: 25-3, title: 'GA-1441 13MM', pdf: '131.pdf'}];
document.querySelector('#control-buttons').addEventListener('click', ({target}) => {
if (!target.closest('button')) return;
document.querySelector('#pdf-links').innerHTML = (target.innerText === 'Кнопка 1')
? arr.map(e => `<div><a id="${e.id}" href="${e.pdf}">${e.title}</a></div>`).join('')
: '';
})
document.querySelectorAll('.stats').forEach(e => {
let conversion = (+e.querySelector('[title="Продано"]').textContent / +e.querySelector('[title^="Просмотров:').textContent) * 100
e.insertAdjacentHTML('beforeend', `<div title="Конверсия" class="col-mbs-6"><span class="flaticon-monitor"></span>${conversion.toFixed(1)}</div> `);
})