I have two buttons and want to use eventlisteners before buttons declaration. But first alert does not shows. How to fix that?
<body>
<script>
window.onload = function() {
const bt1 = document.getElementById('btn1');
bt1.addEventListener('click', function (event) {
alert('bt1 case');
});
}
</script>
<script>
window.onload = function() {
const bt2 = document.getElementById('bt2');
bt2.addEventListener('click', function (event) {
alert('bt2 case');
});
}
</script>
<button id='bt1'> bt1 </button>
<button id ='bt2'> bt2 </button>
</body>