I'm currently working on implementing an accordion feature where I am using custom arrow icons (pngs) as the toggle buttons. The idea is that when you click on the red down arrow, it changes to a blue up arrow to collapse the section, and vice versa.
Although I managed to make it work with the code below, I encountered an issue when trying to apply the same functionality to multiple accordions using the same arrow icons. Despite modifying the IDs and updating the JavaScript accordingly, only the first accordion seems to toggle properly.
Is there anyone who can assist me in achieving this desired behavior across all sets of images?
HTML:
<img src="/wp-content/uploads/2019/08/accordion-open.png" alt="accordion icon" id="accordion" onclick="change();"></div>
JS:
var image_tracker = 'open';
function change(){
var image = document.getElementById('accordion');
if(image_tracker=='open'){
image.src='/wp-content/uploads/2019/08/accordion-close.png';
image_tracker='close';
}
else{
image.src='/wp-content/uploads/2019/08/accordion-open.png';
image_tracker='open';
}
}