Last active
August 29, 2015 14:17
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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