0
Need on Sololearn's Code Playground
Why is my script (code below) giving me an error on the JS block but it's working if I put it on HTML <script></script>? https://code.sololearn.com/W1RtNXI85H7a/?ref=app
2 odpowiedzi
+ 2
Answer is quite simple, Sololearn by default links our script to head tag, so when you write your js in JS tab then you are selecting element before it is even created.
You have to wait for it to load using onload event of window.
window.onload = function() {
document.getElementsByTagName("li")[2].style.color= "red";
}
0
🔫 Rick it's working fine now, thanks brother.