Creé un bucle de div como miniaturas de imágenes en las que se puede hacer clic y cada div obtiene un método onclick mientras que el bucle for pero si hago clic en las miniaturas, no llama a mi función test().
No se donde esta el fallo.
Estaría muy feliz por cada ayuda.
hay alguna solución para hacer esto?
estoy sentado desde horas en ese problema pero sin éxito.
¡Muchas gracias por las ayudas!
<head> <title>Bootstrap Example</title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.1/dist/css/bootstrap.min.css"> <script src="https://cdn.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.slim.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.1/dist/umd/popper.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.1/dist/js/bootstrap.bundle.min.js"></script> </head> <style> .album-container { display: flex; flex-wrap: wrap; background-color: white; } .album-container > div { background-size: cover; background-position: center; background-repeat: no-repeat; width: 115px; height: 115px; margin: 10px; cursor: pointer; border:1px solid lightgray; } .album-container > div:hover{ opacity: 0.7; transition-duration: 0.5s; width: 120px; height: 120px; } </style> <script> function test(){ alert("HELLO"); } </script> <body> <div class="container album-container"> <?php $path = 'pics/gallery'; $files = scandir($path); $files = array_diff(scandir($path), array('.', '..')); foreach($files as $file){ echo '<div class="photo_thumb" id="'.$file.'" onclick="test()" style="background-image:url(pics/gallery/'.$file.')"></div>'; } ?> </div> </body>