I know there are many topics about this, but they address some variable issue. Mine is much more simple, but it is not working. Only works once.
var bt1;
document.addEventListener('DOMContentLoaded', load);
function load() {
document.body.innerHTML += '<div>welcome</div>';
bt1 = document.getElementById('bt1');
bt1.onclick = clicked;
}
function clicked() {
document.body.innerHTML += '<div>welcome</div>';
}
<body>
<button id="bt1">Click me</button>
</body>
I tried taking the clicked function in and out of the onclick statement (as some other topics suggested).
I also tried moving the bt1 variable declaration around (and not using a variable at all).