+ 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
3 ответов
+ 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()">
+ 4
you need to wait until all HTML elements are loaded before you can select the via JS. Therefore use:
window.onload = function () {
code
}
+ 3
Oh, thank you guys. I forgot about this rule. 😅