title: JavaScript toggle class on current element
body: <p>Just want to understand a principle of JavaScript, I'm a bit new to this.</p>
  
  <p>I'm adding some styling to some element which are slides which I'm scrolling through.</p>
  
  <p>The "current" <code>div</code> have a <code>transform: none</code> applied, the two others get styled depending on where I am on the slider. </p>
  
  <p>I'm using this code which is working fine.</p>
  
  <pre><code>el.style.transform = i === e.current ? 'none' : i &gt; e.current ? 'translateX(100%)' : 'translateX(-100%)'
  </code></pre>
  
  <p>My question is how do I add / toggle a <code>class</code> to the current <code>el</code>, and remove it back when it's not the current anymore.</p>
  
  <p>I've tried some couple options using the same principle but can't find the right way to achieve it.</p>
  
  <pre><code>el.classList = i === e.current.toggle('classname') : i &gt; ? e.current.toggle('classname')
  
  el.classList.toggle() = i === e.current ? 'active' : i &gt; e.current ? 'prev' : 'next'
  </code></pre>
  
  <p>Can somebody give me a heads up on how to achieve what i want to do? I've tried to go through some others post on Stack Overflow and to look on <code>element.classList</code> docs everywhere i could find it, but I'm stuck at this point and JS knowledge is not my strong point.</p>
  
  <p>Thanks!</p>