Brooku Brooku - 4 days ago 4
jQuery Question

jQuery rearrange <li> in <ol>?

I'm trying to rearrange my list when a button is clicked, where the first one moves last, second moves fourth, third stays third and fifth moves first, it doesn't seem to take any effect, even the console is not showing anything.

$(document).ready(function() {
$("#rearranage").click(function() {

$.fn.orderChildren = function(order) {
this.each(function() {
var el = $(this);
for (var i = order.length; i >= 0; i--) {
return this;




<div class="hyperlinks">
<ol class="lists">
<li><a id="first" href="">this</a></li>
<li><a id="second" href="">is</a></li>
<li><a id="third" href="">a</a></li>
<li><a id="fourth" href="">test</a></li>
<li><a id="fifth" href="">!</a></li>
<button class="button" id="rearrange">rearrange this!</button>

mjw mjw

I made a fiddle for you:


<div class="hyperlinks">
  <ol class="lists">
    <li class="block-item"><a id="first" href="">this</a></li>
    <li class="block-item"><a id="second" href="">is</a></li>
    <li class="block-item"><a id="third" href="">a</a></li>
    <li class="block-item"><a id="fourth" href="">test</a></li>
    <li class="block-item"><a id="fifth" href="">!</a></li>
<input type="submit" id="rearrange">


   $($(".block-item").get().reverse()).each(function() {

Your hyperlinks will now be reversed when the rearrange button is clicked.