Wednesday, March 24, 2010

jQuery Random Filter

http://blog.mastykarz.nl/jquery-random-filter/

This is awesome by the way. I've made one small change that apparently makes it more browser compatible.


$(function() {

$.jQueryRandom = 0;
 $.extend($.expr[":"],
 {
     random: function(a, i, m, r) {
         if (i == 0) {
             jQuery.jQueryRandom = Math.floor(Math.random() * $(r).size());
         };
         return i == jQuery.jQueryRandom;
     }
 });
// hide a random div on your page
$("div:random").hide();

});

No comments:

Post a Comment