title: Sorting list items up and down not with drag and drop
body: <p>I want a user to be able to reorder a list on a click event. Here is my code:</p>
  
  <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>$(function() {
  
    $('#reOrder li').each(function, (index) {
  
      $(this).attr('id', index);
  
    });
  
    $("#reOrder").delegate("li", "click", function() {
  
      var $indexItem = $(this).index('#reOrder li');
  
      var $thisTxt = $(this).text();
  
      var $prevTxt = $(this).prev('li').text();
  
      $($thisTxt).replaceWith($prevTxt);
  
      //alert($thisTxt);
  
      //alert($prevTxt);
  
    });
  
  });</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;ul id="reOrder"&gt;
    &lt;li&gt;Item 1&lt;/li&gt;
    &lt;li&gt;Item 2&lt;/li&gt;
    &lt;li&gt;Item 3&lt;/li&gt;
    &lt;li&gt;Item 4&lt;/li&gt;
  &lt;/ul&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>So in this example I would like to move the clicked li item and its contents to the position above in the DOM. I suppose strictly speaking it is being moved down in the index of li items.</p>
  
  <p>This is going to be extended later to include buttons that move li items up and down and a submit button that saves the order/state of the list items.</p>
  
  <p>I have found a lot of info on drag and drop (which is not required) but not much on this sort of functionality.</p>