Skip to content Skip to sidebar Skip to footer

Uncaught Typeerror: Cannot Read Property 'id' Of Null

I'm trying to create an html5 audio player. It's for a radio station, so I need the player to reload the source and start playing from 'currrentTime=0;' when the stream starts agai

Solution 1:

You have no element in your markup that has the id player. So when you tell JS to getElementById, it can't find anything. So the value becomes 'null'. After that you call player.id - this is the same as trying to call the property id of an object that doesn't exist.

To fix: Give your player the attribute id="player" or change the selection call. There are other ways to select elements.

document.getElementById(id_string)
document.getElementsByTagName(tag_name)
document.getElementsByClassName("class_values")
document.getElementsByName("name_value")
document.querySelector(css_selector)
document.querySelectorAll(css_selector)

Post a Comment for "Uncaught Typeerror: Cannot Read Property 'id' Of Null"