jQuery - .Ready fires on div tag not in the page
<p>I have implemented below function in a separate .js script file which I load in my main page (Asp.net mvc).</p>

<p>The call back to server is rather costly but ok if specifically requested on the sub-page / content page on which my div tag needs to be filled.</p>

<p>My problem is that the code runs on every page, including pages where the div tag is not present.</p>

<p>How can I remedy my code?</p>

<p>Any comments welcome,
Thanks, Anders, Denmark</p>

<pre><code>jQuery("divStatWrapper").ready(function()
    { 
    jQuery.getJSON("/Statistics/GetPointsDevelopment", 
        function(json)
        {
            jQuery("#divStatWrapper #divStatLoading").fadeOut(1000);

           var jsonPoints = new Array();

            jQuery.each(json.Points, function(i, item)
            {
                jsonPoints.push(item.PlayerPoints );
            });

            jsonPoints.reverse();

           var api = new jGCharts.Api();
            jQuery('&lt;img&gt;') 
            .attr('src', api.make({
                data : jsonPoints,
                type : "lc",
                size : "600x250"
                })) 
            .appendTo("#divStatContents"); 

            jQuery("#divStatWrapper #divStatContents").fadeIn(1000);

        });
    });
</code></pre>

<p>html:</p>

<pre><code>    &lt;%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %&gt;

    &lt;%@ Import Namespace="AJF.Op.Web.MVC.SpilMerePool.Helpers" %&gt;
    &lt;asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server"&gt;
        &lt;center&gt;
            &lt;table id="statisticsTable" classname="statisticsTable"&gt;
                &lt;tr valign="top" align="center"&gt;
                    &lt;td&gt;
                        &lt;%Html.RenderPartial(SMPControls.QueueStatus.ToString(), null); %&gt;
                    &lt;/td&gt;
                    &lt;td&gt;
                        &lt;h2&gt;
                            Statistik - udvikling i point over tid&lt;/h2&gt;
                        &lt;h3&gt;
                            (Alle resultater frem til løbende dato)&lt;/h3&gt;
                        &lt;div id="divStatWrapper"&gt;
                            &lt;div id="divStatLoading"&gt;
                                &lt;img src="../../Images/ajax-loader.gif" /&gt;
                                &lt;span&gt;Loading&lt;/span&gt;
                            &lt;/div&gt;
                            &lt;div id="divStatContents"&gt;
                            &lt;/div&gt;
                        &lt;/div&gt;
                    &lt;/td&gt;
                &lt;/tr&gt;
            &lt;/table&gt;
        &lt;/center&gt;
    &lt;/asp:Content&gt;
</code></pre>
