Thursday, 9 May 2019

html - Javascript - getElementById() returns null even though the element exists




I'm trying to get the element with getElementById(), but it returns null.



This is the error I get on mozilla firefox debugger




"TypeError: document.getElementById(...) is null".




What is wrong in the code?








Stack




Frame One


Frame Three


Frame Two









Answer



top appears to be a reserved variable -- it resolves to window.top in your function. Try naming top something else like _top and you shouldn't get any errors.


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