Reverse the order of the children of a specific element

http://stackoverflow.com/questions/21381468/how-to-reorder-list-items-jquery/21381759

by hibbard_eu

HTML

<ul>
    <li>666</li>
    <li>555</li>
    <li>444</li>
    <li>333</li>
    <li>222</li>
    <li>111</li>
</ul>

<button>Reverse order</button>

JavaScript

$.fn.reverseChildren = function() {
  return this.each(function(){
    var $this = $(this);
    $this.children().each(function(){ $this.prepend(this) });
  });
};

$("button").on("click", function () {
    $("ul").reverseChildren();
});