+ 3

What's wrong with this?

Hello. Can somebody tell me, what's wrong with my code? I am trying to use what I learned in JavaScript and HTML courses. I want to change value of progress bar, but I cant select it. https://code.sololearn.com/WCNV4drAAYK1/?ref=app

18th May 2018, 2:02 PM
Jan Štěch
Jan Štěch - avatar
3 Antworten
+ 14
The script is being run before the window is loaded, therefore the script can not find the progress bar element. try: window.onload = function() { bar = document.getElementById("bar"); bar.value="73"; } or put your JavaScript into a function and call it from a tag e.g <body onload = "functionName()">
18th May 2018, 2:08 PM
jay
jay - avatar
+ 4
you need to wait until all HTML elements are loaded before you can select the via JS. Therefore use: window.onload = function () { code }
18th May 2018, 2:09 PM
Aaron Eberhardt
Aaron Eberhardt - avatar
+ 3
Oh, thank you guys. I forgot about this rule. 😅
18th May 2018, 2:10 PM
Jan Štěch
Jan Štěch - avatar