lundi 5 février 2018

Randomly selecting two elements of a given class and hiding all others?

I have a series of elements with the class .random-related. There's a variable amount that will have this class at any given time, but it's around 15 - 20 elements. What I am trying to do is to take two random examples and .hide() the rest.

I'm considering doing something like $('.random-related').toArray(), shuffling that array using a prewritten shuffle function, and then selecting indices 0 and 1. However, I'm not sure how to turn the array back into a set of jQuery objects that I can then traverse and apply any methods to.

What would be the best way to go about this?




Aucun commentaire:

Enregistrer un commentaire