title: Does the location of script matter in Jquery?
body: <p>Could someone tell me if the location of the script tag matters while using JQuery?</p>
  
  <p>For example:</p>
  
  <pre><code>&lt;script&gt;
   $("a").click(function(event) {
     event.preventDefault();
     $('&lt;div/&gt;')
        .append('default ' + event.type + ' prevented')
        .appendTo('#log');
   });
  &lt;/script&gt;
  
  &lt;a href="http://jquery.com"&gt;default click action is prevented&lt;/a&gt;
  &lt;div id="log"&gt;&lt;/div&gt;
  </code></pre>
  
  <p>The above code does not work as needed but the following works,</p>
  
  <pre><code>&lt;a href="http://jquery.com"&gt;default click action is prevented&lt;/a&gt;
  &lt;div id="log"&gt;&lt;/div&gt;
  &lt;script&gt;
  $("a").click(function(event) {
     event.preventDefault();
     $('&lt;div/&gt;')
        .append('default ' + event.type + ' prevented')
        .appendTo('#log');
  });
  &lt;/script&gt;
  </code></pre>
  
  <p>Why did the second one work? Is it because the code is working serially, top to bottom? Also, if the first code is inside <code>.ready()</code>, then the position does not matter.  </p>