New course! Every coder should learn Generative AI!
Try a free lesson+ 1
what's wrong with this code
<span id="four"> </span > in HTML document.getElementById('four').style.backgroundColor='grey' in JS
2 Answers
+ 2
This Lgtm, try posting the whole code for context
+ 2
Hi, there's not much context, but maybe your js is executing before span element's rendering.
So you can try using window.onload like this:
window.onload = function() {
document.getElementById('four').style.backgroundColor='grey';
}
Then add something to your spam to see the change, like:
<span id="four"> Hello! </span>
Good luck!