Beginner here. So for my class .active
I am setting the order to -1 in my CSS so that it becomes the top div, it removes the class correctly but I am assuming that the order for the previous active is still -1
const divs = document.querySelectorAll('.div');
toggleActive = () =>
{
if (this.classList.includes("active"))
this.classList.toggle("active");
else
{
divs.forEach(x => x.classList.remove("active"));
this.classList.toggle("active");
}
}
divs.forEach(x => x.addEventListener("click", toggleActive));
Basically I have: div1 div2 div3 div4 div5 and if the user clicks one it should result as div4 div1 div2 div3 div5
click again should result div2 div1 div3 div4 div5 but i get instead div4 div2 div1 div3 div5
CSS:
.active
{
order: -1;
}