I am trying to create a simple jquery text rotator: I have a span in which text should fade in and out. There are similar questions here on stackoverflow but I can't apply their solutions to my situation Here is what I wrote so far and I was wondering why this code doesn't work:
var i=0;
function rotate(spanid,w1,w2,w3){
var myspan = "#"+spanid;
var words = [w1,w2,w3];
$(words[i]).appendTo(myspan).fadeIn(2000).delay(2000).fadeOut(2000);
i==words.length? i=0:i++;
rotate(spanid,w1,w2,w3);
}
Is the approach to the problem correct? Why isn't this code working? Thank you all in advance!
EDIT The code isn't working as nothing is showing up. Here is the html section relative to the function:
<p>Blah blah blah <span id="rotate"></span> blah blah blah </p>
<script>
$(rotate("rotate","word1","word2","word3"));
</script>
See Question&Answers more detail:os