hi happy new year for all I have this problem with.style it shows this error in the console
Uncaught TypeError: Cannot read property '0' of undefined at HTMLImageElement.show (Slideshowmodal.js:15)
do you have any idea what I am messing up?
initmodal(); function initmodal() { modalclick = document.getElementsByClassName('Slideshowimg'); for (i = 0; i < modalclick.length; i++) { modalclick[i].onclick = function show() { Modalarts = this.parentNode.parentNode.getElementsByClassName("modalria"); for (j = 0; j < this.parentNode.children.length; j++) { this.Modalarts[j].style.display = "block"; if (this.parentNode.children[j] == this) { index = j; } } this.Modalarts[index].style.display = "block"; } } };
<div id="myModalriaArt" class="modalria"> <span class="closer cursor" onclick="closeModal()">×</span> <div class="modal-content-ria"> <img class="Slideshowimgmodal" src="./imgs/Riaarts/1/Main1.jpg" style="width:100%" alt="You left a big holedasdasda 30x40"> <img class="Slideshowimgmodal" src="./imgs/Riaarts/1/RA1Z2.jpg" style="width:100%" alt="You left a big hole 30x40"> <!-- --> </div> </div>
initmodal(); function initmodal() { modalclick = document.getElementsByClassName('Slideshowimg'); for (i = 0; i < modalclick.length; i++) { modalclick[i].onclick = function show() { Modalarts = this.parentNode.parentNode.getElementsByClassName("modalria"); for (j = 0; j < this.parentNode.children.length; j++) { this.Modalarts[j].style.display = "block"; if (this.parentNode.children[j] == this) { index = j; } } this.Modalarts[index].style.display = "block"; } } }; const cross = document.getElementById('cross').addEventListener('click', () => { document.getElementById("myModalriaArt").style.display= "none"; },false);
<div id="myModalriaArt" class="modalria"> <span id="cross" class="closer cursor">×</span> <div class="modal-content-ria"> <img class="Slideshowimgmodal" src="./imgs/Riaarts/1/Main1.jpg" style="width:100%" alt="You left a big holedasdasda 30x40"> <img class="Slideshowimgmodal" src="./imgs/Riaarts/1/RA1Z2.jpg" style="width:100%" alt="You left a big hole 30x40"> </div> </div>
Modalarts is defined as a local variable, so no need for "this" in front.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.