I have managed to make this work, but I am considering if there is a more efficient solution. My objective is to modify the divs using classes exclusively.
I aim to toggle 4 classes with just one click.
First, I obtain the class for the button and then add a "click" event listener. Within the function, I select all 4 classes using querySelectorAll and assign them to a variable named slide.
const slide = document.querySelectorAll('.header__btn, .wrap__content, .content__aside, .nav');
I understand that querySelector grabs elements in the order they appear in the HTML. I am only selecting elements that will remain constant.
My goal is to toggle a class list for each of these elements. What is the most efficient approach?
Currently, I am using:
slide[0].classList.toggle('header__btn--animate');
slide[1].classList.toggle('wrap__content--slide');
slide[2].classList.toggle('content__aside--slide');
slide[3].classList.toggle('nav--slide');
They toggle classes simultaneously, which is the desired behavior for me.
Is there a better method for achieving this?
Thank you