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?
This can happen if the JavaScript code is executed before the page is fully loaded, so its not able to find the element. The solution is that you need to put your JavaScript code after the closure of the HTML element or more generally before < /body > tag.
HTML DOM Document getElementById() The getElementById() method returns an element with a specified value. The getElementById() method returns null if the element does not exist. The getElementById() method is one of the most common methods in the HTML DOM.
A commonly-used alternative to document. getElementById is using a jQuery selector which you read about more here.
getElementById() The Document method getElementById() returns an Element object representing the element whose id property matches the specified string. Since element IDs are required to be unique if specified, they're a useful way to get access to a specific element quickly.
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.
All these results in null
:
document.getElementById('volume'); document.getElementById('bytesLoaded'); document.getElementById('startBytes'); document.getElementById('bytesTotal');
You need to do a null check in updateHTML like this:
function updateHTML(elmId, value) { var elem = document.getElementById(elmId); if(typeof elem !== 'undefined' && elem !== null) { elem.innerHTML = value; } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With