New course! Every coder should learn Generative AI!
Try a free lesson+ 3
You are changing the div background not the body's.
Change the function to
function dark(){
document.body.style.backgroundColor="black";
document.body.style.color="white";
}
or in ES6
function dark(){
Object.assign(document.body.style, {
backgroundColor: 'black',
color: 'white'
});
}
+ 2
Zainul Khan Give some height to your div.
y.style.height = '100vh'
or change the background color of body tag. You are changing the background color of div.