title: JS: Sort List Items based on data-element
body: <p><strong>I want to sort a list with items. The sorting should be based on the data-element of each item.</strong></p>
  
  <p>The strange thing is, it <strong>works if you try it locally</strong> on your pc (download my sortingtest.html), <strong>but it doesn't work</strong> online in jfiddle, neither and more importantly on mobile phones!</p>
  
  <p>Do you have an idea whats wrong with my code or how I could do it better so that it works also on mobile phones?</p>
  
  <p><strong>The Code:</strong></p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
      &lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"&gt;&lt;/script&gt;
      &lt;script&gt;
      function sortEntries() {    
          var elems = $('#mylist').children('li').remove();
          elems.sort(function(a,b){ 
              return parseInt($(b).data('vote')) &gt; parseInt($(a).data('vote'));
          });
          $('#mylist').append(elems);
      }
      &lt;/script&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
  
      &lt;ul id="mylist"&gt;
          &lt;li data-vote="2"&gt;Vote: 2&lt;/li&gt;
          &lt;li data-vote="4"&gt;Vote: 4&lt;/li&gt;
          &lt;li data-vote="1"&gt;Vote: 1&lt;/li&gt;
          &lt;li data-vote="5"&gt;Vote: 5&lt;/li&gt;
          &lt;li data-vote="3"&gt;Vote: 3&lt;/li&gt;
      &lt;/ul&gt;
  
      &lt;a href="#" onClick="sortEntries();"&gt;Sort me!&lt;/a&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>JFiddle:</strong>
  <a href="http://jsfiddle.net/Q82Qu/" rel="nofollow">http://jsfiddle.net/Q82Qu/</a></p>
  
  <p><strong>HTML-File Download:</strong> (Save file as)
  <a href="https://copy.com/c0Ogb8wLtRrg" rel="nofollow">https://copy.com/c0Ogb8wLtRrg</a></p>
  
  <p>Big thanks in advance,
  Stee</p>