0👍
✅
your approach should work, you just need to load the page before loading your script
using defer
<script src="methods.js" defer></script>
..or put the script at the bottom of your body tag.
Source:stackexchange.com