Cоздаю сайт кинотеатра на js
Не могу понять, как сделать так, чтобы нормально определяло ряд и номер места при клике на кнопку. Буду благодарен за помощь
let cinemaHall = document.querySelector('.cinemaHall');
for(let i = 0; i < 30; i++) {
for(let j = 0; j < 5; j++) {
cinemaHall.innerHTML += `
<p class="seats" data-color="greenColor"></p>
`;
}
}
let seats = document.querySelectorAll('.seats');
for(let i = 0; i < seats.length; i++) {
let seatsAtr = seats[i].getAttribute('data-color');
seats[i].onclick = function() {
if(seatsAtr == "greenColor") {
this.style.backgroundColor = 'red';
seatsAtr = "redColor";
seats[i].textContent = i+1;
} else {
this.style.backgroundColor = 'green';
seatsAtr = "greenColor";
seats[i].textContent = '';
}
}
}