Hey guys I'm building a simple modal for a fantasy ecommerce website, I want for the modal to show information dynamically based on which product the user clicks, I am trying to just do it with JavaScript by editing the styles, but I can't get querySelectorAll to actually close all of the different text id's, so that when I open up one modal, the second one I open comes with the text from the last one overlayed on top ... Is this the best way to go about? If so, how can I fix this issue?
document.querySelector('#item1').addEventListener('click',
function(){
document.querySelector('.bg-modal').style.display = 'flex';
document.querySelector('#modalTxt1').style.display = 'inline-block';
document.querySelector('#modalImg1').style.display = 'inline-block';
});
document.querySelector('#item2').addEventListener('click',
function(){
document.querySelector('.bg-modal').style.display = 'flex';
document.querySelector('#modalTxt2').style.display = 'inline-block';
document.querySelector('#modalImg2').style.display = 'inline-block';
});
document.querySelector('.close').addEventListener('click',
function(){
document.querySelector('.bg-modal').style.display = "none";
document.querySelectorAll('#modalTxt1 #modalTxt2 #modalTxt3 #modalTxt3 #modalTxt4 #modalTxt5 #modalTxt6').forEach(el => {
el.style.display = "none";
});
});