Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

JavaScript object can be used to modify element.style by using the following syntax:

  1. Get the DOM element you want to modify:
var myElement = document.getElementById("my-element");
  1. Access the style object of the element:
var elementStyle = myElement.style;
  1. Set the properties and values you want to modify:
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.