title: Sortable divs with jQuery
body: <p>I have page that has sorting for divs. Basically you can click button and it's sorts divs below. This works fine. Now I would like to extend it a bit but not sure how. What I would like it to do is, that when you press for example year sorting button once, its sorts DESC but when click again, then it sorts ASC.</p>
  
  <p>So here is my current implementation:</p>
  
  <pre><code>function sorting(parent, childSelector, sortKey) {
      var items = parent.children(childSelector).sort(function(a, b) {
          var vA = $(sortKey, a).text();
          var vB = $(sortKey, b).text();
          return (vA &lt; vB) ? -1 : (vA &gt; vB) ? 1 : 0;
      });
      parent.append(items);
  }
  
  $('#sPrice').data("sortKey", "span.price");
  $('#sStyle').data("sortKey", "span.style");
  $('#sYear').data("sortKey", "span.year");
  
  $(".sort").click(function() {
     sorting($('#sortThis'), '.sortable', $(this).data("sortKey"));
  });
  </code></pre>
  
  <p>HTML &amp; jQuery example is here: <a href="http://codepen.io/anon/pen/NPGrJB" rel="nofollow">http://codepen.io/anon/pen/NPGrJB</a></p>
  
  <p>So what I want that if user clicks for example Style once, it sorts DESC, if clicks again then sorts ASC.</p>