When I add event handlers to objects in html using jQuery, do I have to call $.ready(function(){ ... })?
<p>I am constructing a page which uses jQuery to assign event handlers. Now I am assigning onclick events to functions but does the page run the script and then construct the HTML or does the page construct HTML and then run the script?</p>

<pre><code>&lt;script type="text/javascript"&gt;
    function opinionbyid(popinionid){
        $.post("index.php", {"opinionid":popinionid}, function(data){
            var data2 = JSON.parse(data);
            $(".opinion").html(data2.opinion);
            $(".note").html(data2.note);
        }, "json");
    }
    function loginform() { $(".middle").html($(".loginform").html()); }
    function registerform() { $(".middle").html($(".registerform").html()); }
    function opinionpostform() {};
    $("#loginbutton").click(function(){
        //UNSURE, MAYBE I SHOULD DO IT IN $.ready(function(){ HERE }))
    });
&lt;/script&gt;
</code></pre>

<p>like</p>

<pre><code>$.ready(function(){ 
    $("#loginbutton").click(function(){
        // code...
    });
})
</code></pre>

<hr>

<p>so far I habitually used script tags in the head section. this is why I think I should use $.ready() because assigning handlers to obects is done after objects are loaded, in jquery's documentation example.</p>

<pre><code>&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
  &lt;style&gt;
  p { color:red; margin:5px; cursor:pointer; }
  p.hilite { background:yellow; }
  &lt;/style&gt;
  &lt;script src="http://code.jquery.com/jquery-latest.js"&gt;&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
  &lt;p&gt;First Paragraph&lt;/p&gt;
  &lt;p&gt;Second Paragraph&lt;/p&gt;
  &lt;p&gt;Yet one more Paragraph&lt;/p&gt;
&lt;script&gt;
    $("p").click(function () { 
      $(this).slideUp(); 
    });
    $("p").hover(function () {
      $(this).addClass("hilite");
    }, function () {
      $(this).removeClass("hilite");
    });
&lt;/script&gt;

&lt;/body&gt;
&lt;/html&gt;
</code></pre>

<p>after solution edit:
In the end, I thought "why am I handling the events with script anyway?" now I am using </p>

<pre><code>onClick="dosomething()"
</code></pre>

<p>on button properties. no need to complicate anything.</p>
