what's wrong with this code | Sololearn: Learn to code for FREE!
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

15th Dec 2023, 3:42 PM
Charbel
2 Answers
+ 2
This Lgtm, try posting the whole code for context
15th Dec 2023, 3:58 PM
Mohammed shoaib
+ 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!
15th Dec 2023, 4:47 PM
Mariano Fregosi
Mariano Fregosi - avatar