function shuffleContent(container) { var content = container.find("> *"); var total = content.length; content.each(function() { content.eq(Math.floor(Math.random() * total)).prependTo(container); }); } $(function() { shuffleContent($(".item_wrapper")); });