Create a jQuery Random Filter

Submitted by:Jhon Brain

Date added:07 March, 2013

Category:jQuery

This simple and handy jQuery filter return a single random item from a selection of items. Credit to Waldek Mastykarz

Tags: random filter

Code Snippet:

Usage:
$('item:random').text();


jQuery.jQueryRandom = 0;
jQuery.extend(jQuery.expr[":"],
{
random: function(a, i, m, r) {
if (i == 0) {
jQuery.jQueryRandom = Math.floor(Math.random() * r.length);
};
return i == jQuery.jQueryRandom;
}
});
 
 

Comments