I created a loop of div's as image thumbnails that can be clicked and every div gets an onclick method while the for loop but if i click on the thumbnails, it doesn't call my function test().
I don't know where the failure is.
I would be very happy for every help.
is there any solution to do this?
i am sitting since hours on that problem but without success.
Thanks a lot for helps!
<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>