I have problem with simple Javascript code not working from linked file in header but working in browser console for instance. Code is:
document.getElementById("displayname").onfocus = function(){alert("Hello");}
In chrome inspector I can see that script file is linked properly and I can access it in sources tab. I also get this error in loaded script file.
Uncaught TypeError: Cannot set property 'onfocus' of null
What's wrong here?