how to toggle class of parent in javascript code example

Example 1: how to toggle class of parent in javascript

/* HTML */

/*
<div class="tab-links closed">
	<a class="tab-links__link" onclick="toggleLink(this)"></a>
    <a class="tab-links__link" onclick="toggleLink(this)"></a>
    <a class="tab-links__link" onclick="toggleLink(this)"></a>
    <a class="tab-links__link" onclick="toggleLink(this)"></a>
</div>
*/

const toggleLink = (element) => {
 element.parentNode.classList.toggle('closed');
}

Example 2: 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');
}