I made a very simple way to do this. See if it fits your example:
$('.item').each(function(i){
var rdm = Math.floor(Math.random()*$('.item').length-1)
$(this).before($('.item').eq(rdm));
})
In case, just change the class .item
by desired. To leave only the first item of the class, just do this:
$('.item').not('.item:first').hide();
Other option
Ney, correct me if I’m wrong, but your purpose seemed to me to be this: to hide all the elements of a class, but leaving the show only one element and that the choice of this is random. If that’s the case, you can just do it like this:
$(document).ready(function(){
var rdm = Math.floor(Math.random()*$('.item').length-1)
$('.item').not($('.item').eq(rdm)).hide();
})
In Jsfiddle just give one run that it will change the order randomly.
But for what you have in question, goes the first option. And another thing, to have a better view remove the br
.
You want those elements to have a class
.exemplo
are re-ordered every time the page opens is that? Why don’t you do it on the server?– Sergio
there are lines for example line 1 - class 1 - class 2 .... line 2 - class 1 - class 2 ...
– Ney
like this <div> Class1, class2, .... </div> <div> Class1, class2, .... </div>
– Ney
Why don’t you do it on the server?
– Sergio
will be my first site, I do not know how to do it right rs if you have a youtube link or some page that helps in this I would be very grateful :)
– Ney
something like that? http://jsfiddle.net/qEM8B/
– Chun
yes it would be more or less that yes, but the remaining 6 days can not appear thanks :) I will test the way of Samir
– Ney