I have the following which works perfectly
$(function() {
// Create the chart
chart = new Highcharts.StockChart({
...
});
});
However when I make the following modification
createCharts();
function createCharts() {
// Create the chart
chart = new Highcharts.StockChart({
...
});
}
I get the following error message
Message: ‘Highcharts’ is undefined
Nothing else has changed why does the above break my script?
In your first example, the function is called when the document is ready (ie, after the HighCharts script has been loaded). In your second example, the HighCharts script is probably defined after the script you’re running so you need to either wait for document ready:
… or change the order of your scripts: