Cannot run script properly with my custom plugin

I’m pretty new with wordpress developing. What I’m trying to do is to add javascript to my plugin. It seems to be loaded, because when I’m console loging something like ‘test’ it works fine. But when I’m trying to query anything (for example document.querySelector(‘#only-for-test’)) or even (‘body’), it gives me back ‘null’…