I have an svg icon that on click, I want it to rotate 180 degrees. Currently, only the first icon toggles the class, but I'm trying to get all icons to toggle.
I'm not sure what I'm missing...
let accordionChevron = document.querySelector('.rotate');
accordionChevron.addEventListener('click', function() {
this.classList.toggle('down');
})
.rotate {
transition: all 0.2s ease-in-out;
}
.rotate.down {
transform: rotate(180deg);
}
<svg class="rotate" fill="none" height="11" viewBox="0 0 16 11" width="16" xmlns="http://www.w3.org/2000/svg">
<path d="m0 2.82837 2-2 6 6 6-6 2 2-8 8.00003z" fill="#000a70"></path>
</svg>
<hr>
<svg class="rotate" fill="none" height="11" viewBox="0 0 16 11" width="16" xmlns="http://www.w3.org/2000/svg">
<path d="m0 2.82837 2-2 6 6 6-6 2 2-8 8.00003z" fill="#000a70"></path>
</svg>