how to toggle class of parent in javascript

Solutions on MaxInterview for how to toggle class of parent in javascript by the best coders in the world

showing results for - "how to toggle class of parent in javascript"
Luka
04 Aug 2019
1/* HTML */
2
3/*
4<div class="tab-links closed">
5	<a class="tab-links__link" onclick="toggleLink(this)"></a>
6    <a class="tab-links__link" onclick="toggleLink(this)"></a>
7    <a class="tab-links__link" onclick="toggleLink(this)"></a>
8    <a class="tab-links__link" onclick="toggleLink(this)"></a>
9</div>
10*/
11
12const toggleLink = (element) => {
13 element.parentNode.classList.toggle('closed');
14}
Jen
15 Jan 2020
1/* HTML
2<div id=”menuIcon” onclick=”menuAnimate()”>
3  <div class=”bar”></div>
4  <div class=”bar”></div>
5  <div class=”bar”></div>
6</div>
7*/
8
9// Javascript
10 menuAnimate = () => {
11  const main = document.getElementById('menuIcon');
12  main.classList.toggle('rotate');
13  let c = document.getElementById('menuIcon').children;
14  c[0].classList.toggle('rotateL');
15  c[1].classList.toggle('slick');
16  c[2].classList.toggle('rotateR');
17}