+ 6

How can we change the background color of our page using javascript .

I want to change the background color of the page but it doesn't work . The JavaScript code is : code = "ff0ce7"; change = document.getElementById('test'); change.bgcolor = code; Why does it not works . Plz help

17th Aug 2017, 1:47 AM
RZK 022
RZK 022 - avatar
2 Respostas
+ 6
try this trick js part: function changeBackground(color){ document.body.style.background; } html part: <body onload="changeBackground('red')">
17th Aug 2017, 2:04 AM
Raz
Raz - avatar
+ 3
thanks but I want to add a random color code . How can I do that .
17th Aug 2017, 11:16 AM
RZK 022
RZK 022 - avatar