Try the following:
$(document).ready(function() {
var paras = $('div.myWords p');
var rand = Math.floor(Math.random() * paras.length);
paras.eq(rand).addClass('show');
});
If you are trying to change display: noneto display: block, you can omit the class showfrom your CSS and show it using only jQuery, for example:
$(document).ready(function() {
var paras = $('div.myWords p');
var rand = Math.floor(Math.random() * paras.length);
paras.eq(rand).show();
});
By the way, you need to change your CSS in order to redefine the work. Change display: hidden;to display: none;and add a class div.myWordsto the second rule:
div.myWords p { display: none; }
div.myWords p.show { display: block; }
source
share