Last active
August 29, 2015 14:03
-
-
Save maxxcrawford/63e9cc1fc208bc04002f to your computer and use it in GitHub Desktop.
Randomize Child Elements
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$.fn.randomize = function(selector, callback) { | |
var $elems = selector ? $(this).find(selector) : $(this).children(), | |
$parents = $elems.parent(); | |
$parents.each(function() { | |
$(this).children(selector).sort(function() { | |
return Math.round(Math.random()) - 0.5; | |
// }). remove().appendTo(this); // 2014-05-24: Removed `random` but leaving for reference. See notes under 'ANOTHER EDIT' | |
}).detach().appendTo(this); | |
}); | |
callback && callback(); | |
return this; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment