'Trying by a script-tag in the html-flow to add eventlistener to html-body onload-event doesn't work. Is it a race condition?

In the middle of the html-body I have

<script>
function justfortest() {
    alert('teste');
}
document.getElementById('idbody').addEventListener('onload',justfortest);
</script>

(I copied the line just as it is in my html, without linebreaks.)

But it doesn't fire. It's a rather short html-body, so I wonder if this simply not get called because the onload-event of the html-body has already passed, before the eventlistener is added properly, and how I could check that?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source