I have 8 divs to select from, they all have id's assigned to them, named not numerically, but descriptively. I want to be able to add .myClass to a div chosen at random out of these eight.
To generate a random number, I would use this JavaScript snippet:
var random = Math.round(Math.random()*10);
My questions:
- How can I limit the random number to only 1 out of 8 possible values?
- How can I add .myClass to a randomly chosen one div out of eight with a non-numeric id?