jQuery - .Ready fires on div tag not in the page
- by Anders Juul
Dear all,
I have implemented below function in a separate .js script file which I load in my main page (Asp.net mvc).
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.
My problem is that the code runs on every page, including pages where the div tag is not present.
How can I remedy my code?
Any comments welcome,
Thanks, Anders, Denmark
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('<img>')
.attr('src', api.make({
data : jsonPoints,
type : "lc",
size : "600x250"
}))
.appendTo("#divStatContents");
jQuery("#divStatWrapper #divStatContents").fadeIn(1000);
});
});