i am writing a jQuery file using onClick() to be an event for a button. But i want to load another js function from an external js file. How can i do that ? i have been trying but no result
This is my main.js
$(document).ready(function(){
    $("#dashboard").on("click", function(event){
        event.preventDefault();
        $('#content').html(dashboardTemplate);
        // I want another js external file will be loaded here
    });
});
This is my external js file: The element #btnAddGroup is inside dashboardTemplate which is just a html file
    $("#btnAddGroup").on("click", function (event) {
        event.preventDefault();
        alert('test');
    });
Thank you
Edit : Based on your suggestion
external.js
function addGroup(){
    $("#btnAddGroup").on("click", function (event) {
        event.preventDefault();
        alert('test');
    });
}
main.js
$(document).ready(function(){
    $("#dashboard").on("click", function(event){
        event.preventDefault();
        $('#content').html(dashboardTemplate);
         $.getScript('external.js', function() {
            addGroup();
        });
    });
});
Its still not working. I am trying troubleshoot. thanks again
 
     
    