I have two JavaScript files. The first file, a.js, checks the screen size and loads file b.js if the screen size is less than 600 pixels. After the condition satisfies, I am calling a constructor function that is defined in file b.js. But it is giving me reference error that the function is not defined.
jQuery(document).ready(function() {
jQuery(window).on("load", function() {
const MinPx = 600;
function downloadJS() {
var x = document.createElement('script');
x.type = 'text/javascript';
x.src = '/js/b.js';
document.body.appendChild(x);
}
if (jQuery(document).width() > MinPx) {
downloadJS();
new tpc("Homepage", jQuery("#a"));
}
});
});
}` before the `document.body.appendChild(x)` line.
– Namaskar Sep 21 '17 at 18:04