title: how to use Jquery writing a click event ? Which way is correct?
body: <p>I'm new in Jquery. I have a problem in my code, i'm very confused that which way is correct when writing jquery code for click event. Please help me and explain thanks in advance !</p>
  
  <p>first method :</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  
  $('a').click(function(){ 
      alert('you clicked a tag !!! ');
  });
  
  &lt;/script&gt;
  </code></pre>
  
  <p>and second method :</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
          $(document).ready(function(){
              $('a').click(function(){ 
                  alert('you clicked a tag !!! ');
              });
          });
  
  &lt;/script&gt;
  </code></pre>
  
  <p>when i write 2 method for testing, just the second one is successful and display a alert, but the first one do nothing. In addition i review on <a href="http://api.jquery.com/click/" rel="nofollow">http://api.jquery.com/click/</a> the first one is the way they write sample but it run successfully, that make me confused .</p>
  
  <pre><code>&lt;script&gt;
      $("p").click(function () { 
        $(this).slideUp(); 
      });
      $("p").hover(function () {
        $(this).addClass("hilite");
      }, function () {
        $(this).removeClass("hilite");
      });
  &lt;/script&gt;
  </code></pre>