I would like to loop through a collection of divs and randomly fade them out when a click event is triggered but at the moment I have to continually click to fade the other divs all out. I would rather click a div and have all its divs randomly fade out. I have added some console.logs into the while loop and everything seems to work fine, problem is when I try to fadeout the actual elements. If anyone could help that would be great?
Fiddle here: http://jsfiddle.net/kyllle/sdpzJ/7/
I'm not sure if I understand your question, but here's a possible solution:
function randomFadeOut(i){  
    var random;
    var e = 0;
    while (e < ctnLength) { 
        random = Math.random() * 1000;
        $(ctn[e]).not(i).delay(random).animate({ opacity : 0 });
        e++;
    }        
}
This will fade out all the divs at random times when you click on one.
I updated your fiddle here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With