I'm attempting to make a button display random element when clicked using show/hide. It sets up so the element will be hidden first to stop duplicates, then shown. However it sometimes doesn't show.
The Fiddle will be clearer than my explanation: http://jsfiddle.net/qAfqN/.
Simplified code:
this.uiSelect = function(){
var length = $("#ui li").length;
var ran = Math.floor(Math.random()*length);
$('#ui li').hide();
$("#ui li:nth-child(" + ran + ")").show();
};
$(document).ready(function(){
$('#mangle').click(function(){
uiSelect();
});
});