I'm trying to change the class of an specific div that i click, using this:
let divs = document.querySelectorAll('.x');
function idk(){
Array.prototype.forEach.call(divs, function(element) {
element.classList.add('y');
Array.prototype.forEach.call(divs, function(element) {
element.classList.remove('x');
});
});
}
.y{
transition: 0.5s;
transform: rotateY(180deg);
}
<div id="d1">
<div id="c1" class="x" onclick="idk()">a</div>
<div id="c2" class="x" onclick="idk()">b</div>
<div id="c3" class="x" onclick="idk()">c</div>
</div>
This code above works well, but only in all div
s at the same time, not with only that I've clicked