jQuery doesn't work in <head>?
<p>This code is supposed to make a slideshow out of stacked list-elements (I commented out the CSS so I can see what's going on) by fading out the topmost elements until only the first one is visible, then fade in the topmost element and the rest and start anew. If I put the script below my content inside the <code>&lt;body&gt;</code> and throw out the <code>$(function() {</code> it works perfectly fine, but in the <code>&lt;head&gt;</code> nothing happens. I wrote this yesterday and today I still can't see the mistake, so I'm posting it here.</p>

<pre><code>&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
    &lt;title&gt;&lt;/title&gt;
    &lt;style type="text/css"&gt;
        ul {
            position: relative;
        }
        ul li {
            /*position: absolute;
            left: 0;
            top: 0;*/
        }
    &lt;/style&gt;
    &lt;script src="jquery-1.5.1.min.js" type="text/javascript"&gt;&lt;/script&gt;

    &lt;script type="text/javascript"&gt;
        $(function() {
            var i = 0;
            var count = $('ul li').size();      

            function fade() {
                if (i &lt; count-1) {
                $('ul li:nth-child('+(count-i)+')').fadeOut(300);
                    i++;
                } else {
                    $('ul li:nth-child('+count+')').fadeIn(300, function(){$('ul li').show();});    
                    i = 0;
                }
            }

            $('button').click(function() {
                setInterval('fade()', 1000);
            });
        });
    &lt;/script&gt;
&lt;/head&gt;

&lt;body&gt;
    &lt;button&gt;Slideshow GO!&lt;/button&gt;
    &lt;ul id="slider"&gt;
        &lt;li&gt;&lt;img src="1.jpg" /&gt;&lt;/li&gt;
        &lt;li&gt;&lt;img src="2.jpg" /&gt;&lt;/li&gt;    
        &lt;li&gt;&lt;img src="3.jpg" /&gt;&lt;/li&gt;
        &lt;li&gt;&lt;img src="4.jpg" /&gt;&lt;/li&gt;
    &lt;/ul&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>

<p>Thanks</p>
