Try this, for myself i simply created a utility class for rotating the svg icon-down.
.rotate--180deg {
transform: rotate(180deg);
}
When the svg icon-down is being clicked, i will add this class to the element and it will rotate 108deg which will make the icon look upside.
const showAnswer = document.querySelectorAll(".show-answer");
for (let i = 0; i < showAnswer.length; i++) {
showAnswer[i].addEventListener("click", function () {
showAnswer[i].classList.toggle("rotate--180deg");
// This will add or remove the utility class whenever the icon is clicked
);
}
<img
class="show-answer"
src="../images/icon-arrow-down.svg"
alt="chevron-down"
/>
look at my github to see how i done it. https://github.com/subu-v/FAQ-accordian-card.git