jquery/javascript select option randomly
问题 I want to select an option from select randomly. <select class=".sel" id="sel"> <option>a</option> <option>b</option> <option>c</option> <option>d</option> </select> actually i am using jQuery autocomplete. Well,the question is how can i select option randomly from a select box ? and what i tried is function change_something(opt) { var randomOption=Math.floor(Math.random()*$(opt+' option').size()); $(opt+ option["value='"+randomOption+"'"]).attr('selected', 'selected'); } Actually i am not a