Incorporating a bootstrap theme into my project has required me to include several javascript files. The challenge arises when some pages load dynamic content from the server, resulting in the entire HTML not being present when the javascript files are executed.
This causes issues with event handlers not being able to bind to dynamically loaded HTML elements. As a workaround, I have been loading the scripts after the AJAX call completes, but I find this solution to be somewhat makeshift. Here's an example of what I've been doing:
$.get("/path/to/rest/call", function(data) {
$('#htmlElement').html(data);
}).done(function() {
$.getScript("/path/to/js/file.js");
});
I believe there must be a more elegant approach to resolve this issue. Any suggestions?