I'm trying to display a bunch of divs in a random order with 4 divs in each of them. Those have to be in a random order too. My code:
var cards = $(".qcards").get();
cards.sort(function() {
return Math.random()*30 > 5 ? 1 : -2;
});
$.each(cards,function(i,el) {
var color = this.className,
$el = $(el);
$el.css({backgroundColor: color}).appendTo( $el.parent() );
});
var answers = $(".answer").get();
answers.sort(function() {
return Math.random()*30 > 5 ? 1 : -2;
});
$.each(answers,function(i,el) {
var color = this.className,
$el = $(el);
$el.css({backgroundColor: color}).appendTo( $el.parent() );
});
There are 40 .qcards and in each of those 4 .answer
Somehow this isn't working in IE, there's no error message/code though. The only statement I get when I'm debugging is "'return'" statement outside of function. Is it possbile that .get() isn't working in IE?
Aucun commentaire:
Enregistrer un commentaire