Skip to content

Instantly share code, notes, and snippets.

@jacopotarantino
Created March 9, 2016 23:29
Show Gist options
  • Save jacopotarantino/724b277a0bea5e513e7c to your computer and use it in GitHub Desktop.
Save jacopotarantino/724b277a0bea5e513e7c to your computer and use it in GitHub Desktop.
Randomly sort children of a div using jQuery
window.jQuery(function () {
'use strict';
var $parent = $('.gallery-grid-fullwidth');
$('> *', $parent)
.sort(function () {
return ( Math.round( Math.random() ) - 0.5 )
})
.appendTo($parent);
});
@jacopotarantino
Copy link
Author

  • Waits for document.ready event.
  • Swap out the selector on line 4 to random-sort the children of a different selector.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment