It says that TypeError: document.getElementById(...) is null

mcan picture mcan · Dec 14, 2012 · Viewed 117.7k times · Source

Althought I pushed a parameter to getElementById I wonder from where is this 'is null' error coming from?

TypeError: document.getElementById(...) is null
[Break On This Error]   

document.getElementById(elmId).innerHTML = value;

Line 75  

In addition to this i wonder why title and time did not show unless I click one of these playlist pictures?

Answer

Olemak picture Olemak · Aug 1, 2014

Make sure the script is placed in the bottom of the BODY element of the document you're trying to manipulate, not in the HEAD element or placed before any of the elements you want to "get".

It does not matter if you import the script or if it's inline, the important thing is the placing. You don't have to put the command inside a function either; while it's good practice you can just call it directly, it works just fine.