title: Storing Sortables in localStorage
body: <p><a href="http://jsfiddle.net/2H2rx/" rel="nofollow">http://jsfiddle.net/2H2rx/</a></p>
  
  <p>Having Trouble retaining changes to the last item in a sortable list.</p>
  
  <pre><code>$( "#sortable" ).sortable();
  $( "#sortable" ).on("sortupdate",function( event, ui ) {
        var sorted = $( this ).sortable( "serialize");
        console.log(sorted);
        localStorage.setItem('sorted', sorted) ;
  
  });
  
  if(localStorage.getItem("sorted") !== null){
    var arrValuesForOrder = localStorage.getItem('sorted').substring(6).split("&amp;div[]="); 
  
    var $ul = $("#sortable");
    $items = $("#sortable").children();
  
  // loop backwards so you can just prepend elements in the list
  // instead of trying to place them at a specific position
    for (var i = arrValuesForOrder[arrValuesForOrder.length - 1]; i &gt;= 0; i--) {
      // index is zero-based to you have to remove one from the values in your array
      $ul.prepend( $items.get((arrValuesForOrder[i] - 1)));
    }
  }
  
  $( "#sortable" ).disableSelection();
  </code></pre>
  
  <p>I'm trying to code a way to store sortables in local storage.  I'm having a little trouble that seems to hinge on the last item, and it happens intermittently, after a few times.  Something is breaking it?  It will not load changes to the last item after a few times, or will arbitrarily reorder them.  I can't tell.   To replicate, you must load link, reorder a few times, run a few times, reorder some more.  It eventually wont retain the changes to the last item, at least in Chrome 27.0.1453.110 m.  Haven't checked other browsers.</p>
  
  <p>I see a bunch of other questions asking similar things to this, but I've actually got a semi-working solution now, just having trouble debugging.</p>
  
  <p>Edit:  It appears that the error happens when #1, 2, or 3 is in the final position.  Maybe not a rule, but that's an easier way for me to replicate it.</p>