title: Why do adding and removing a class from a div onclick not working?
body: <p>I'm trying to do this: clicking a <code>&gt;</code> to show a list and a <code>V</code>, click again to close the list and change <code>V</code> back to <code>&gt;</code>. Here is my code</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>function toggle() {
  
    var toggleClosed = $(this).find(".toggle-closed");
    var toggleOpened = $(this).find(".toggle-opened");
  
    if (!$(toggleClosed).is(":visible")) {
      toggleClosed.removeClass('toggle-opened').addClass('toggle-closed');
      toggleOpened.removeClass('toggle-closed').addClass('toggle-opened');
    } else {
      $(toggleClosed).addClass('toggle-closed').removeClass('toggle-opened');
      $(toggleOpened).addClass('toggle-opened').removeClass('toggle-closed');
    }
  }</code></pre>
  <pre class="snippet-code-css lang-css prettyprint-override"><code>.form-row-filter {
    background-color: grey;
  }
  
  .toggle-opened {
    cursor: pointer;
    display: block;
  }
  
  .toggle-closed {
    cursor: pointer;
    display: none;
  }
  
  .material-icons {
    margin-right: -4px;
    margin-left: 4px;
    vertical-align: middle;
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"&gt;&lt;/script&gt;
  &lt;div class="form-row-filter" style="display:inline-block"&gt;
    &lt;ul&gt;
      &lt;div class="material-icons toggle-opened" onclick="toggle()"&gt;&amp;gt;&lt;/div&gt;
      &lt;div class="material-icons toggle-closed" onclick="toggle()"&gt;V&lt;/div&gt;
      &lt;li class="toggle-closed"&gt;
        company a
      &lt;/li&gt;
      &lt;li class="toggle-closed"&gt;
        company b
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>Here is a codepen: </p>
  
  <p><a href="https://codepen.io/thinkvantagedu/pen/MNORvZ?editors=1100" rel="nofollow noreferrer">https://codepen.io/thinkvantagedu/pen/MNORvZ?editors=1100</a></p>
  
  <p>Why wouldn't the class being added or removed?</p>