Добрый день. Есть проблема. Есть карточки людей. Как сделать, чтобы при клике открывалось своё модальное окно ?
let userProf = '<div style="list-style-type: none">';
for (let i = 0; i < DATA.length; i++) {
userProf += "<div class='main'>" + "<div class=\"textcols-item show-modal\">" + "<div class=\"trigger\">" + "<h3>" + DATA[i].name + "</h3>" +
"<br>" + "<br>" +
"<i class=\"icono-iphone\"></i>" + " " + " " + "<span>" + DATA[i].phone + "</span>" +
"<br>" + "<br>" +
"<i class=\"icono-mail\"></i>" + " " + " " + "<span>" + DATA[i].email + "</span>" + "</div>" + "</div>" + "</div>" + "</div>" +
"<div class=\"modal hidden\">" + "<button class=\"close-modal\">×</button>" + "<span>" + DATA[i].name + "</span>" + "</div>"
;
}
document.getElementById("result").innerHTML = userProf;
document.getElementById('search').onkeyup = function() {
document.getElementById('result').innerHTML = '';
let searchText = this.value.toLowerCase();
let stringLength = searchText.length;
if (stringLength > 1) {
for (let i = 0; i < DATA.length; i++) {
let userName = DATA[i].name.split('').slice(0, stringLength).join('').toLowerCase();
let userPhone = DATA[i].phone.split('').slice(0, stringLength).join('').toLowerCase();
let userEmail = DATA[i].email.split('').slice(0, stringLength).join('').toLowerCase();
if (userName == searchText || userEmail == searchText) {
document.getElementById('result').innerHTML += "<div class='main'>" + "<div class=\"trigger\">" + "<li class='list' style='list-style-type: none;'>" + "<h3>" + DATA[i].name + "</h3>" +
"<br>" + "<br>" +
"<i class=\"icono-iphone\"></i>" + " " + " " + "<span>" + DATA[i].phone + "</span>" +
"<br>" + "<br>" +
"<i class=\"icono-mail\"></i>" + " " + " " + "<span>" + DATA[i].email + "</span>" + "</li>" + "</div>" + "</div>" + "</div>" + "<br>" + "<br>";
}
}
} else {
document.getElementById("result").innerHTML = userProf;
}
};
'use strict';
const modal = document.querySelector('.modal');
const overlay = document.querySelector('.overlay');
const btnClose_modal = document.querySelector('.close-modal');
const btnsOpenModal = document.querySelectorAll('.show-modal');
const openModal = function () {
modal.classList.remove('hidden');
overlay.classList.remove('hidden');
};
const closeModal = function () {
modal.classList.add('hidden');
overlay.classList.add('hidden');
};
for (let i = 0; i < btnsOpenModal.length; i++) {
btnsOpenModal[i].addEventListener('click', openModal);
}
btnClose_modal.addEventListener('click', closeModal);
overlay.addEventListener('click', closeModal);
//Handling an Esc_Keypress Event
document.addEventListener('keydown', function (e) {
if (e.key === 'Escape' && !modal.classList.contains('hidden')) {
closeModal();
}
});