0
Why does changing color by using js doesn't work
Why is this js code doesn't work https://code.sololearn.com/W2BTjj3i2AS7/?ref=app Note: this is my first code so it's quite ugly
6 odpowiedzi
+ 3
Try to use
window.onload=()=>{
var p=document.getElementById("p");
p.style.backgroundColor="blue";
}
+ 1
Your HTML contens load before the JavaScript so you have to write JavaScript code inside the window.onload function so your Javascript code will execute after loading HTML contents.
window.onload = function () {
//Your code
}
0
Thanks
0
#HrCoder sorry but can you explain why?
0
Use @ instead of #
0
Thank you HrCoder