Categories
JavaScript Answers

How to change the background color with JavaScript?

Spread the love

Sometimes, we want to change the background color with JavaScript.

In this article, we’ll look at how to change the background color with JavaScript.

How to change the background color with JavaScript?

To change the background color with JavaScript, we can set the style.background property of an element.

For instance, we write

document.body.style.background = color;

to set the body element’s background color to color.

We get the body element’s background color with

document.body.style.background

Conclusion

To change the background color with JavaScript, we can set the style.background property of an element.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *