I am trying to create something of a shuffle effect. I grab some data consisting of firstname and lastname from an xml file. then i randomly select one, assign it to a span, fade it in and fade it back out. I do this for a few names to give the effect of shuffling through the list of names.
it was working fine until i tried to explicitly set the span text to a value. Below is an example of my code (yes i am not very well verse with jquery at all) $('input[name="btnGet"]').click(function(e) { e.preventDefault(); var spanName = $('span#contestant_name'); for (var x = 0; x <= 15; x++) { spanName.fadeIn('slow'); spanName.fadeOut('slow', setRandContestant); if (x == 15) { spanName.text('Cecil'); spanName.fadeIn('slow'); } } } so what i expected this to do is shuffle through the names and when the variable x is 15 just show whatever name i set. however whats happening is that the name is set first and then the code in the for loop is run ...... I noticed the same thing if i put an alert(' ') at the end of the script; the alert fires first and then the fade animations are run. Could someone please tell me what i am doing wrong ?