I'm trying to randomize an array with DOM elements, like this:
var allTargets=$('#target1, #target2, #target3, #target4');
var randomTargets=null;
randomTargets = allTargets[Math.floor(Math.random() * allTargets.length)];
console.log(randomTargets);
In the console I can see the array is shuffled each time I refresh the page. But when I try to trigger a method with the randomTargets variable, the program crashes. Something like this:
randomTargets.hide();
But without the random variable, the program works:
var allTargets=$('#target1, #target2, #target3, #target4');
allTargets.hide();
What am I doing wrong?