Friday, 13 December 2019

jquery - javascript:Uncaught TypeError: Cannot read property 'addEventListener' of null




Why am I getting this error? This should work, what I'm trying to do is when someone selects the form on the upload the image file. Thanks



The error I keep getting is



    










But it was not working fine


Answer



Put your JavaScript in the below of the body.
It throws error because your JavaScript first works when your DOM doesn't ready.



And it is a good practice to load all scripts at the end of the body















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 ...