Check Object Exists throws Object Required Error
<p>I have a web form for data entry.  The page requires an ID to be passed via query string.  In the code behind I check the ID has been supplied. If it hasn't the form (in a panel) is hidden and an error message is displayed.</p>

<p>In the html I have a JQuery script block that attaches an event (downloaded date picker). </p>

<pre><code>    window.onload = function() {
        new JsDatePick({
            useMode: 2,
            target: "txtDateOfIncident",
            dateFormat: "%d %M %Y"
        });
    };
</code></pre>

<p>If the code behind hides the form the JQuery throws an error <code>Object Required</code></p>

<p>So in the JQuery I am trying to test existance of the object <a href="http://stackoverflow.com/questions/5293041/jquery-how-to-check-if-an-element-exists" title="Found here">As per this post</a>... </p>

<pre><code>    window.onload = function() {
        if ($('#txtDateOfIncident').length) {
            new JsDatePick({
                useMode: 2,
                target: "txtDateOfIncident",
                dateFormat: "%d %M %Y"
            });
        }
    };
</code></pre>

<p>Now I get the <code>Object Required</code> error on the <code>$('#txtDateOfIncident').length</code> code.</p>

<p>Any help to resolve this would be appreciated.</p>
