In some cases, jQuery cannot find the function due to scope problems . You can define a function as shown below, and an important task is to set the global scope of the function:
jQuery(document).ready(function($) {
function sample() { console.log('blah blah'); }
window.sample = sample;
})
or shorter form as shown below:
(function($) {
function sample() { console.log('blah blah'); }
window.sample = sample;
})(jQuery)
Hope this helps.
source
share