When i click a button on index.html to load test.html dynamically, the javascript which is written in test.html does not work.
test.html below.
<p>Test for dinamic loaded javascript</p>
<button id="testButton"></button>
<script>
const testElem = document.querySelector('#testButton');
testElem.addEventListener('click', testFunction);
function testFunction() {
alert('Hello World');
}
</script>
the script below loads test.html dynamically.
fetch('/test.html').then(function(response) {
return response.text();
}).then(function(string) {
const laden = document.querySelector("#demo");
laden.innerHTML = string;
console.log(string);
}).catch(function(err) {
console.log('Fetch Error', err);
});