How to change background color in JavaScript?

To change background color in JavaScript, do this: element.style.backgroundColor = 'yellow'.

For example, if this is your element with some text in it:

<span id="my-text">Hello World!</span>

Then you can change the background color behind Hello World! to, say, yellow with this JavaScript:

document.getElementById('my-text').style.backgroundColor = 'yellow';