-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript04.js
More file actions
42 lines (37 loc) · 1.37 KB
/
script04.js
File metadata and controls
42 lines (37 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
const buttons = document.querySelectorAll('button')
buttons.forEach(function(button){
button.addEventListener('click',function(event){
handleClick(event)
})
})
/**
* Функция обрабатывает клик по кнопке в карточке товара и попеременно вызывает
* функции для показа или скрытия текста о товаре.
* @param {MouseEvent} clickedButtonEvent
*/
function handleClick(clickedButtonEvent){
const cardNode = clickedButtonEvent.target.parentNode;
const card ={
wrap: cardNode,
img: cardNode.querySelector('img'),
productName: cardNode.querySelector('.productName'),
button: cardNode.querySelector('button')
}
const textOnButton = card.button.innerText;
if(textOnButton ==='Подробнее'){
showMoreText(card);
} else if(textOnButton === 'Отмена'){
hideMoreText(card);
}
}
function showMoreText(card){
card.img.style.display = 'none';
const text = 'Описалово картинки';
card.productName.insertAdjacentHTML('afterend', `<div class="desc">${text}</div>`)
card.button.innerText ='Отмена';
}
function hideMoreText(card){
card.img.style.display = 'block';
card.wrap.querySelector('.desc').remove();
card.button.innerText ='Подробнее';
}