title: How to toggle elements' class from an `onClick` event (from jQuery to pure JS)?
body: <p>I want to toggle a css class on all elements with the same class, on click of another element.</p>
  <p>I had it working with jQuery but need to switch to pure JavaScript.</p>
  <p>The jQuery version that works:</p>
  <pre class="lang-js prettyprint-override"><code>$(function() {
    $(&quot;#logo&quot;).click(function() {
      $(&quot;.grey&quot;).toggleClass(&quot;white&quot;, 1000);
      $(&quot;.red&quot;).toggleClass(&quot;orange&quot;, 1000);
    });
  });
  </code></pre>
  <p>When you click on the element with <code>id=&quot;logo&quot;</code>, everything with <code>class=&quot;grey&quot;</code> toggles <code>white</code> class and everything with <code>class=&quot;red&quot;</code> toggles <code>orange</code>.</p>
  <p><strong>Update with new problem!</strong></p>
  <p>I'm using @Vektor's code which works well — except on the iPhone 5 where nothing happens. (It works in my iPhone 12 and 7.) Simplified code for trials:</p>
  <pre><code>&lt;body&gt;
      
  &lt;div id=&quot;logo&quot;  class=&quot;grey&quot;&gt;&lt;p class=&quot;red&quot;&gt;Hello.&lt;/p&gt;
  &lt;/div&gt;
  
  &lt;script&gt;
  
      const logo = document.getElementById('logo');
      
      logo.addEventListener('click', () =&gt; {
          const grey = document.querySelectorAll('.grey');
          const red = document.querySelectorAll('.red');
          grey.forEach(e =&gt; e.classList.toggle('white'));
          red.forEach(e =&gt; e.classList.toggle('orange'));
      }, false);
  &lt;/script&gt;
  &lt;/body&gt;
  </code></pre>
  <pre><code>body{background-color: #000000;}
  div#logo{
    position:fixed;
    top:0;
    left:0;
    height: 100vh;
    width:30vw;
    cursor: pointer;
  }
  .red{background-color:#4C0000;}
  .orange{background-color:#d69215}
  .grey{background-color:#485055;}
  .white{background-color:white;}
  </code></pre>
  <p>I read adding <code>cursor:pointer</code> would fix JavaScript not functioning on non-traditional clickable elements for older iPhone browsers. It didn't.</p>