I am working on a client based HTML-based site and refreshes a page on a set of divisions randomly Sorting is required. I usually handle it via PHP and a database call, but this is a static site.
So, I'm thinking that anyone knows how a set of divas is displayed randomly to use jquery?
Here's an example:
& lt; Div class = "myItems" & gt; & Lt; Div class = "item" & gt; 1 & lt; / Div & gt; & Lt; Div class = "item" & gt; 2 & lt; / Div & gt; & Lt; Div class = "item" & gt; 3 & lt; / Div & gt; & Lt; / Div & gt;
Upon refresh, it may change in:
& lt; Div class = "myItems" & gt; & Lt; Div class = "item" & gt; 2 & lt; / Div & gt; & Lt; Div class = "item" & gt; 3 & lt; / Div & gt; & Lt; Div class = "item" & gt; 1 & lt; / Div & gt; & Lt; / Div & gt;
How does anyone know this?
Actually it's pretty simple:
$ (" MyItems "). Html ($ (". MyItems .item"). Sort (function () {return Math.random () - 0.5;}));
That's it! enjoy.
Comments
Post a Comment