On loading a page I add an event listener to a form.
window.onload=function()
{
document.getElementById("login").addEventListener("submit", function(event){
event.preventDefault()
});
}
When I reload the page it sometimes works and sometimes I get the message Cannot read properties of null (reading 'addEventListener').
It's about a 50/50 chance.
What could be the problem here?