Answers for "how to toggle class in children element"

-1

how to toggle class in children element

/* HTML
<div id=”menuIcon” onclick=”menuAnimate()”>
  <div class=”bar”></div>
  <div class=”bar”></div>
  <div class=”bar”></div>
</div>
*/

// Javascript
 menuAnimate = () => {
  const main = document.getElementById('menuIcon');
  main.classList.toggle('rotate');
  let c = document.getElementById('menuIcon').children;
  c[0].classList.toggle('rotateL');
  c[1].classList.toggle('slick');
  c[2].classList.toggle('rotateR');
}
Posted by: Guest on January-04-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language