How to call the inner function jQuery-wrapper $ (function () {}?

I have a changeGraph () function inside a jQuery shell that I need to call somehow from the outside. I need to access the setData function from a jQuery-based graphic library library.

The source is as follows:

function changeGraph(){ // I need to access $.plot.setData somehow }; var d2 = [[0, 0], [20, 300000]]; $(function () { $.plot($("#placeholder"), [{color: "#000000", data: d2}], { series: { lines: { show: true, fill:true, fillColor: {colors: [ "#d1ddea","#8e959d"]}}, points: { show: false } } } ); }); 

How can i do this?

+4
source share
3 answers
 var changeGraph; $(function () { changeGraph = function () { // Need to access $.plot($("#placeholder") here }; }); changeGraph(); // call this when document is ready at least 
+8
source

You must move your function outside the callback function.

+2
source
 function changeGraph() { // ... } $(function() { changeGraph(); }); 
+2
source

All Articles