$(function(){ var variableName = $("#selector").toArray(); var elemlength = variableName.length; var randomnum = Math.floor(Math.random()*elemlength); var randomitem = variableName[randomnum]; $(randomitem).css("display", "block"); });