This problem was happening because I was trying to bind an
HTML element before it was created.
My script was loaded on top of the
HTML (in the head) but it needed to be loaded at the bottom of my
HTML code (just before the closing body tag).
Thanks for your attention James Allardice.
A possible workaround is using
Use this if the script is not going to generate any document content. This will tell the browser that it can wait for the content to be loaded before loading the script.
Hope it helps.