Skip to content
Advertisement

JQuery object shuffle / randomize

Hi I have a JQuery object with multiple divs inside each containing text:

JavaScript

I want to copy the object and shuffle the divs inside so that when I display the new object, it will be a shuffled version of the original object. Is this possible with a JQuery object or am I going to have to store the divs in an array, and if so can someone tell me how I could achieve this?

Advertisement

Answer

Use a generic shuffle algorithm (e.g. the Fisher-Yates shuffle) and pass your object as the argument, e.g.

JavaScript
JavaScript
Advertisement