$ = jQuery; $(document).ready(function(){ reorderCustomCircles(); }); /* Re-order the Custom Circles * Based on the element to have an attribute of "data-order" */ function reorderCustomCircles() { var circles = $('.hentry'), orderAttr = 'data-order'; circles.each(function(){ $this = $(this); // If the circle has been set an order if ( typeof $this.attr(orderAttr) !== 'undefined' && $this.attr(orderAttr) !== false) { var order = $this.attr(orderAttr), // Should only need to check nth-child for the order target = $this.siblings(':nth-child(' + order + ')'); // Move the circle that has an order to that order $this.insertAfter(target); } }); }