I want to open a modal on clicking a link. The link is present in a container/section which is generated through a script tag.
I am loading jQuery, Popper and Bootstrap CSS & JS files inside the script.js (it will be added to third-party websites). The container is displayed with items but the modal does not open.
Page.html
<body>
...
<script src="http://localhost:7000/" type="application/javascript"></script>
</body>
SCRIPT.JS (hosted on express server)
Load jQuery
script.src = 'https://code.jquery.com/jquery-3.3.1.slim.min.js';
script.integrity = 'sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo';
script.crossOrigin = 'anonymous';
document.getElementsByTagName("head")[0].appendChild(script);
Add Bootstrap CSS
script.rel = "stylesheet";
script.href = "https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css";
script.integrity = "sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T";
script.crossOrigin = "anonymous";
document.getElementsByTagName("head")[0].appendChild(script);
Add Popper and Bootstrap JS in Body (functions to load respective url, integrity and crossOrigin)
loadPopper('https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js','sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1','anonymous');
loadBootstrap('https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js','sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM','anonymous');
After this, I have my HTML containing the section with the link.
If I move just the jQuery script tag to Page.html the modal starts to open.
Page.html
<body>
...
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="http://localhost:7000/" type="application/javascript"></script>
</body>
I tried loading the jQuery in 'body' in the script.js (like page.html above), it didn't work.