ŠŠµ рŠ°Š±Š¾Ń‚Š°ŠµŃ‚ document.getElementById | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
- 1

ŠŠµ рŠ°Š±Š¾Ń‚Š°ŠµŃ‚ document.getElementById

ŠŸŃ€Šø Š²Ń‹Š·Š¾Š²Šµ ŠøŠ· Š²Š½ŠµŃˆŠ½ŠµŠ³Š¾ фŠ°Š¹Š»Š° Š½Šµ рŠ°Š±Š¾Ń‚Š°ŠµŃ‚ document.getElementById(id) style.backgroundColor="red";

31st Dec 2017, 2:48 PM
Max bax
Max bax - avatar
5 Respostas
+ 6
Let the HTML load first, so that you can work on it. Reference: https://www.sololearn.com/learn/JavaScript/2758/ window.onload = function() { ...your code } As far as your objective is concerned, you might wanna alter the CSS for the change in its background color: window.onload = function() { document.getElementById("next").style.background="blue"; } The innerHTML property would paste a text (blue) on your rectangle instead.
31st Dec 2017, 3:26 PM
Dev
Dev - avatar
0
thanks
31st Dec 2017, 3:47 PM
Max bax
Max bax - avatar
0
if I place the code in html it's working
31st Dec 2017, 3:49 PM
Max bax
Max bax - avatar
0
but if I place this code in external file it's not working
31st Dec 2017, 3:49 PM
Max bax
Max bax - avatar