<div class="select">
<div class="select__header">
<span class="select__current"> <img src="./img/rus.jpg" alt=""> +7</span>
<span class="select__icon"><img src="./img/Stroke.svg" alt=""></span>
</div>
<div class="select__body">
<div class="select__item"><img src="./img/rus.jpg" alt="">+7</div>
<div class="select__item"><img src="./img/usa.jpg" alt="">+1</div>
<div class="select__item"><img src="./img/Flag_of_Turkey.svg.webp" alt="">+90</div>
</div>
</div>
.select{
width: 110px;
position: relative;
img{
width: 30px;
}
&__header{
border: 1px solid #ccc;
cursor: pointer;
display: flex;
}
&__current{
font-size: 18px;
padding: 8px;
}
&__icon{
display: flex;
justify-content: center;
align-items: center;
flex-shrink: 0;
height: 40px;
width: 15px;
margin-left: auto;
img{
width: 10px;
}
}
&__body{
display: none;
left: 0;
right: 0;
border: 1px solid #ccc;
position: absolute;
top: 100%;
background-color: #fff;
}
&__item{
line-height: 24px;
padding: 8px;
font-size: 16px;
cursor: pointer;
&:hover{
background-color: #ccc;
}
}
}
.select.active .select__body{
display: block;
}
let header = document.querySelectorAll('.select__header')
let item = document.querySelectorAll('.select__item')
let select = document.querySelector('.select')
let images = document.querySelectorAll('.select__item img')
header.forEach(i => {
i.addEventListener('click', () => {
i.parentElement.classList.toggle('active')
})
})
item.forEach(i => {
i.addEventListener('click', () => {
images.forEach(el => {
let text = images[el] + i.textContent,
currentText = select.querySelector('.select__current')
currentText.innerText = text
select.classList.remove('active')
console.log(images);
})
})
})
картинки флагов, при смене страны картинка underfined, не понимаю почему