How to set background color of HTML element using css properties in JavaScript
In this article, you will learn how to set background color of HTML element using css properties in JavaScript.
Using the css background-color property, we can set the background color of an HTML element.
Syntax :
element{background-color:color-name}
Basically, we will create a class with the property of background-color and set its value to red.
.new-class{background-color:red}
And using the javascript setAttribute() method, we will add the new-class to the targeted element.
document.querySelector('div').setAttribute('class', 'new-class');Try it Yourself »
save
listen
AI Answer
How to set background color of HTML element using css properties in JavaScript
0
In this article, you will learn how to set background color of HTML element using css pro…
asked
Apu
0 answers
2915
In this article, you will learn how to set background color of HTML element using css pro…
Answer Link
answered
Apu