Shuffle children with jQuery


/ Published in: jQuery
Save to your folder(s)

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


Copy this code and paste it in your HTML
  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. };

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.