I want to replace an image in a specific serial number using javascript, for the style change in the parent class it works but to change the image it only changes in the first class the code :
<?php
$ssubprod = mysqli_query($conn,"select * from subproduk where idproduk = '$id'");
$nsubprod = mysqli_num_rows($ssubprod);
for($i = 0 ;$i < $nsubprod; $i++){
$r = mysqli_fetch_array($ssubprod);
$idprod = $r[0];
$idsubprod = $r[1];
$subprod = $r[2];
$desk = $r[3];
$harga= $r[4];
$st = $r[5];
?>
<button class="accordion">
<div class="w3-left"><?php echo $subprod; ?></div>
<div class="w3-right w3-margin-right"><img src="./img/pt.png" width="50%" id="panah"></div>
<div class="w3-right w3-margin-right"><?php echo $harga; ?></div>
</button>
<div class="panel">
<p><?php echo $desk; ?></p>
</div>
<?php
}
?>
and the javascript :
<script>
var acc = document.getElementsByClassName("accordion");
var i;
for (i = 0; i < acc.length; i++) {
acc[i].addEventListener("click", function() {
this.classList.toggle("active");
var panel = this.nextElementSibling;
if (panel.style.maxHeight) {
panel.style.maxHeight = null;
document.getElementById('panah').src = "./img/pt.png";
} else {
panel.style.maxHeight = panel.scrollHeight + "px";
document.getElementById('panah').src = "./img/pn.png";
}
});
}
</script>
I want to change the second-order image to pn.png, but what changes is the first-order image