+ 11
I sometimes have some problems with selecting elements from DOM. For example in this code:
var player = document.getElementById("player"); It shows error that cannot find property of undefined or null. Why?
7 ответов
+ 2
If the script tag with the code is above the element with Id "player" in the document, then it will try to get the player element before the element has loaded in. This happens because the script will be executed before everything below it in the document gets the chance to load
You can fix this by moving the script below the element with Id "player" or by making a window.onload function so the code waits until the whole page has fully loaded before doing anything.
+ 10
Thanks everybody! It now works!!!
+ 8
i am sure
+ 3
Um, what do you want to do with the variable "player"?
+ 2
hey guys ,
i still have that problem , i have introduced an id in my script positioned above the script link code but the changes arent still visible ,please help.Am using opera mini and note pad.
+ 1
use php Storm app. it shows u the errors very good
+ 1
:)