title: Sort a list by id by using javascript
body: <p>I'm making a phonegap app on iOS that requires sort a list by time
  I tried add the time to the id of each li item and then sort based on the id </p>
  
  <pre><code>&lt;ul id="test"&gt;
  &lt;li id="4112"&gt;blub&lt;/li&gt;
  &lt;li id="1422"&gt;blaaah&lt;/li&gt;
  &lt;li id="6640"&gt;hmmmm&lt;/li&gt;
  &lt;li id="2221"&gt;one more&lt;/li&gt;
  &lt;/ul&gt;
  </code></pre>
  
  <p>and here is the javascript: </p>
  
  <pre><code>$(function(){
  var elems = $('#test').children('li').remove();
  elems.sort(function(a,b){
      return (new Date(a.id) &gt; new Date(b.id));
  });
  $('#test').append(elems);
  });
  </code></pre>
  
  <p><a href="http://jsfiddle.net/3uYUq/1103/" rel="noreferrer">http://jsfiddle.net/3uYUq/1103/</a></p>
  
  <p>I tried on chrome and it ran well . However, if I tried on phonegap app, the list is not sorted correctly . It doesn't follow any order. Any solution for this ? 
  P/s: Someone said that on Safari it should be (new Date(a.id) - new Date(b.id)) on Safari but seems that it doesn't affect phonegap </p>
  
  <p>Explain more about my phonegap code . This code retrive records from db and show it as list of items on html. </p>
  
  <pre><code>function getAllDeadlines_success(tx, results){
  
  var len = results.rows.length;
  //var s = "";
  $('#allList').empty();
  var tmpDueDate = '1900-01-01';
  var tmpDueTime = '00:00';
  for (var i=0; i&lt;len; i++){
      var allDeadline = results.rows.item(i);
  
      var deadlineDatePart = allDeadline.duedate.split('-');
      var deadlineTimePart = allDeadline.duetime.split(':');
  
      var newDate = new Date(deadlineDatePart[0], deadlineDatePart[1] - 1 , deadlineDatePart[2], deadlineTimePart[0], deadlineTimePart[1], 0, 0);         
      var notiDate = new Date(newDate - 86400*1000);
      //compare with current time
      var result = isLate(allDeadline.duedate, allDeadline.duetime).toString();
      if ( result == "true"){         
          $('#allList').append('&lt;li id = "'+allDeadline.duedate+' '+allDeadline.duetime+'"&gt;&lt;a href="#DeadlineDetail" id = "'+allDeadline.id+'" data-transition = "slide"&gt;'+ allDeadline.class +'&lt;br&gt;'+ allDeadline.duedate+'  '+ allDeadline.duetime+'&lt;br&gt;'+ allDeadline.description +'&lt;/a&gt;&lt;/li&gt;');
          // window.plugin.notification.local.add({
          //  id : getRandomInt(0,99999), 
          //     message: 'Dont forget to complete: '+allDeadline.description+'',
          //     badge: 0,
          //     date: notiDate
          // });
      }
  }
  
  $(function(){
      var elems = $('#allList').children('li').remove();
      elems.sort(function(a,b){
  
          return (new Date(a.id) &gt; new Date(b.id));
      });
  
      $('#allList').append(elems);
  });
  $("#allList").listview().listview('refresh');
  
  }
  </code></pre>