The simple answer is: You cannot call setLayout() with this setting anywhere!
The reason that setLayout() will not be visible outside customize() even from other JavaScript code, because it is locally defined inside customize() , so it has a local scope, accessible only inside customize() . Like others, we mentioned that other ways are possible ... (^ __ ^)
You can return the response of setLayout() by returning it as a customize() method and use it in HTML , for example customize().setLayout('b.html'); eg.
<button onclick="customize().setLayout('b.html');">Click Please</button>
JavaScript:
function customize() { var setLayout = function (text) { var selectedLayout = text; layout += selectedLayout; $.get(layout, function (data) { $("#layout-grid").html(data); }); }; return { setLayout: setLayout }; }
Another approach
You can also define your main function, i.e. customize as Expression of a Expressed Function (IIFE) . This way you can omit the bracket by calling its method in the HTML section.
<button onclick="customize.setLayout('b.html');">Click Please</button>
Javascript
var customize = (function () { var setLayout = function (text) { var selectedLayout = text; layout += selectedLayout; $.get(layout, function (data) { $("#layout-grid").html(data); }); }; return { setLayout: setLayout }; })();
source share