I am using this plugin to create charts: http://www.filamentgroup.com/lab/update_to_jquery_visualize_accessible_charts_with_html5_from_designing_with/
The code works below if I run it via the console in firebug, but if I have it run in when i reload the page it wont load the chart.
I am going to guess its that because the parent element is created after the DOM is loaded.
So I am wondering if I can fire this with jQuery live()? Loads like:
- Request user location
- Display single page view (this is where the element is created via JSON data)
Any ideas on how I can get my plugin to fire once the new element is created?
$('#snow-line').visualize({type:'bar'});
$('#resort-open').visualize({
type:'pie',
colors: ['#658AB6','#FAFAFA']
});
UPDATE:
This is how I am rendering the data via my JSON object
var resortOpenPerc = loadResort.openDownHillPercent;
var ressortOpenDiff = 100-resortOpenPerc;
$("#resort-open tbody tr:eq(0) td:first").html(resortOpenPerc);
$("#resort-open tbody tr:eq(1) td:first").html(ressortOpenDiff);
And this error is rendering:
Index or size is negative or greater than the allowed amount
domain.com/visualize.js
Line 201
No. The
.live()method is deprecated presumably in part because it does not convey the fact that it is mere event delegation.In other words, it works only for handling browser events, not arbitrary code like plugins.
You say the elements are created “with Mustache.js and data is being loaded via JSON”.
I don’t know what that means in your code (because you didn’t post it), but if you don’t have direct access to the new elements as they’re being created, then simply select them after they’ve been added to the DOM, and run the plugin at that time.
If this doesn’t work, then there’s some other issue, and you’ll need to post your code so that we can see the issue.