Posted By

tomsyweb on 11/01/10


Tagged


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

dekehooper
Tyster


Shuffle children with jQuery


 / Published in: jQuery
 

URL: http://css-tricks.com/snippets/jquery/shuffle-children/?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+CSS-TricksSnippets+%28CSS-Tricks+Snippet+Feed%29

Usage: $(".parent-element").shuffleChildren();

  1. $.fn.shuffleChildren = function() {�  � 
  2. $.each(this.get(), function(index, el) {�  �  �  � 
  3. var $el = $(el);�  �  �  � 
  4. var $find = $el.children();�  �  �  � 
  5. $find.sort(function() {�  �  �  �  �  � 
  6. return 0.5 - Math.random();�  �  �  � 
  7. });�  �  �  � 
  8. $el.empty();�  �  �  � 
  9. $find.appendTo($el);�  � 
  10. });
  11. };

Report this snippet  

You need to login to post a comment.