For one of my first ventures into JQuery, I have the very simple goal of stepping through the children of a div and fading them in and out one by one. For some reason though, if I manually define an index for nth-child, say 1, then the first child fades in and out four times. If I use the variable "i", however, then all of the children fade in and out four times. Why is this happening?
Here is my code:
<div id="slideshow">
<p>Text1</p>
<p>Text2</p>
<p>Test3</p>
<p>Text4</p>
</div>
<script>
$(document).ready(function() {
var $elements = $('#slideshow').children();
var len = $elements.length;
var i = 1;
for (i=1;i<=len;i++)
{
$("#slideshow p:nth-child(i)").fadeIn("slow").delay(800).fadeOut("slow");
}
});
</script>
Each of the paragraphs is set to display: none; initially.