title: Move divs with specific class to top
body: <p>On button click, I want to add "active" class to divs that have "sort" class. Then, move divs with "active" class to top position in the container.
  The result will be in this order: 2,4,1,3</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>$('button').click(function(){
    $('.container div').each(function() {
    if($('.container div').hasClass('sort')) {
      $(this).addClass('active').prependTo('.container'); }
    });
  });</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="container"&gt;
    &lt;div&gt;1&lt;/div&gt;
    &lt;div class="sort"&gt;2&lt;/div&gt;
    &lt;div&gt;3&lt;/div&gt;
    &lt;div class="sort"&gt;4&lt;/div&gt; 
  &lt;/div&gt;
  
  &lt;button&gt;click&lt;/button&gt;    </code></pre>
  </div>
  </div>
  </p>