Friday 28 June 2019

html - Why can't javascript find a div that is defined below it?





This works:



  










This doesn't:



  










mybla is null at this point. argh. How can I make this work? Thanks!!!

(and yes, I want the div below the script)


Answer



Because the DOM isn't fully loaded yet. You need to put your code in an onload handler if you want it above the HTML. Like this:






No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...