title: Add audio rows after video rows
body: <p>How can I make sure that audio rows gets added after the video rows with the code below. Note that I want it all in the same table. I assume I shouldn't use <code>prepend()</code> the way I do.</p>
  
  <p>The expected result should look like this if you add 3 video rows and 2 audio rows, no matter what order you add them in:</p>
  
  <pre><code>video 3
  video 2
  video 1
  audio 2
  audio 1
  </code></pre>
  
  <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>var videoCount = 1;
  var audioCount = 1;
  $('input[type="submit"]').on('click', function(e) {
    var type = $('input[name="type"]:checked').val();
    if( type == 'video' )
    {
      var count = videoCount; videoCount++;
    }
    else
    {
      var count = audioCount; audioCount++;
    }
    $('table').prepend('&lt;tr&gt;&lt;td&gt;' + type + ' ' + count + '&lt;/td&gt;&lt;/tr&gt;');
  });</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;label&gt;&lt;input type="radio" name="type" value="video" checked="checked" /&gt; Video&lt;/label&gt;
  &lt;label&gt;&lt;input type="radio" name="type" value="audio" /&gt; Audio&lt;/label&gt;
  &lt;input type="submit" name="submit" value="New Row" /&gt;
  &lt;table&gt;&lt;/table&gt;</code></pre>
  </div>
  </div>
  </p>