I think you've this issue because the script tag is before the div tag. When the page script is loaded, the script doesn't know that the div tag exists and return "underfined".