jQuery - .Ready fires on div tag not in the page
Posted
by Anders Juul
on Stack Overflow
See other posts from Stack Overflow
or by Anders Juul
Published on 2010-05-12T07:04:19Z
Indexed on
2010/05/12
7:14 UTC
Read the original article
Hit count: 679
jQuery
|JavaScript
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);
});
});
© Stack Overflow or respective owner