$.fn.shuffleChildren = function() {
$.each(this.get(), function(index, el) {
var $el = $(el);
var $find = $el.children();
$find.sort(function() {
return 0.5 - Math.random();
});
$el.empty();
$find.appendTo($el);
});
};
Usage
$(".parent-element").shuffleChildren();
See the Pen
jQuery Shuffle Function by Chris Coyier (@chriscoyier)
on CodePen.
this is cool I like it.
Cool, nic1
… and if you want shuffle onload:
<pre>$(window).load(function() {
$(“.shuffle”).shuffleChildren();
});
</pre>
Instead of demo page
<pre>$(“#shuffle”).click(function() {
$(“.shuffle”).shuffleChildren();
});
</pre>
where would I place this? i am somewhat new to coding…I am using dreamweaver, and I have made a js plugin for the code, but where would I put the ‘usage’ aspect?