title: How to move an elements list into another element with the best performance?
body: <p>I have two lists with a lot of items "more than 50" and I need to move to an individual element with all its events.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div id="container"&gt;     
       &lt;div&gt;&lt;ul id="g1"&gt;&lt;/ul&gt;&lt;ul id="g2"&gt;&lt;/ul&gt;&lt;/div&gt;
       &lt;div&gt;&lt;ul id="gFill"&gt;&lt;/ul&gt;&lt;/div&gt;
  &lt;div&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>I have the same number of items in "g1" and "g2" lists, and I need to move them to "gFill" in an interleaved way. </p>
  
  <p>I'm doing with the following script:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var gFill = $("#gFill");
  var g1 = $("#g1");
  var g2 = $("#g2");
  while (true) {
    if ($("li", g1).size() &gt;= $("li", g2).size()) {
      $('li:first', g1).appendTo(gFill);
    }
    else {
      $('li:first', g2).appendTo(gFill);
    }
    if ($("li", g1).size() &lt; 1 &amp;&amp; $("li", g2).size() &lt; 1) {
      break;
    }
  }</code></pre>
  </div>
  </div>
  </p>
  
  <p>Despite moving items good, the performance is too slow. I must to improve the performance, how can I do it?</p>
  
  <p>After that I need the method of inverse, I need to move the items if "gFill" to "g1" and "g2", I did it but is very slow too.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var gIn1 = [], gIn2 = [];
  var g1 = $("#g1");
  var g2 = $("#g2");
  $("li", "#container").each(function (i, e) {
    var item = this;
    if ($("li", g1).size() &lt;= $("li", g2).size()) {
      $(this).appendTo(g1);
    }
    else {
      $(this).appendTo(g2);
    }
  });</code></pre>
  </div>
  </div>
  </p>
  
  <p>It would be great to go asynchronous</p>