- 1

Не работает document.getElementById

При вызове из внешнего файла не работает document.getElementById(id) style.backgroundColor="red";

31st Dec 2017, 2:48 PM
Max bax
Max bax - avatar
5 ответов
+ 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