Ajax load and sidebar

Hello
I am using jquery load function to separate header, footer and sidebar. This way will be not mess the codes and files.
Everything is going fine except the sidebar toggle.

Everything are original codes except the ajax load and separated parts.
Ajax part:

$("#header").load("./partials/header.html");
$("#sidebar").load("./partials/sidebar.html");
$("#footer").load("./partials/footer.html");

The problem is instead toggle the menu, it redirects me to the index.html# .
If I move the sidebar codes back to the index.html then it works.
I tried also to do this to insert the script in the sidebar.html but didn’t change anything. I did try this method too, but didn’t do anything:

$("#sidebar").load("./partials/sidebar.html", function (responseTxt, statusTxt, xhr) {
        if (statusTxt == "success")
            $.getScript("../../assets/vendors/coreui/coreui.bundle.min.js", function () {
  
            });
        if (statusTxt == "error")
            alert("Error: " + xhr.status + ": " + xhr.statusText);
    });

What can be the problem? Do I must change in javascript something or something else?