Skip to content

Instantly share code, notes, and snippets.

@jorgepinon
Last active August 29, 2015 14:17
Show Gist options
  • Save jorgepinon/13074e5b4e0edb89fc07 to your computer and use it in GitHub Desktop.
Save jorgepinon/13074e5b4e0edb89fc07 to your computer and use it in GitHub Desktop.
displays a random item from an unordered list (like for random promo images)
//todo: de-jquery this
function showRandomItem(list) {
// random ad on refresh. Each a element should have style="display:none"
var items = $(list).children('li'),
tot = items.length;
if (tot > 1) {
var randNum = Math.round(Math.random()*(tot-1));
items.eq(randNum).show();
} else {
$(items).show();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment