JavaScript object can be used to modify element.style by using the following syntax:
var myElement = document.getElementById("my-element");
var elementStyle = myElement.style;
elementStyle.backgroundColor = "red";
elementStyle.fontSize = "20px";
Here is a full example:
var myElement = document.getElementById("my-element");
var elementStyle = myElement.style;
elementStyle.backgroundColor = "red";
elementStyle.fontSize = "20px";
This will set the background color of the element to red and the font size to 20 pixels.
Asked: 2021-04-08 11:00:00 +0000
Seen: 8 times
Last updated: Jan 15 '22