Wednesday 12 June 2019

javascript - document.getElementbyId() returning null




In the code at the line marked as //Error in comments. I get Javascript error saying: "Cannot read property style of 'null'". I have no idea what it is not able to find the object. I have thought and tried everything. Please help. Here is the code:










Facebook login









Answer



You are executing your javascript code BEFORE the

was actually created.




Also note that you did not close your

with a corresponding
.



So move your javascript code to a part below your HTML. Or execute it after the page finished loading. If you are using JQuery you can do:





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