Question:easy

Which JavaScript function is used to change the style of an HTML element dynamically?

Show Hint

Real style changes go through the element's style object, like node.style.color.
Updated On: Jul 2, 2026
  • document.getElementById("element").setStyle("color", "red");
  • document.style.change()
  • document.modifyStyle("element").color("red");
  • document.getElementById("element").style.color = "red";
Show Solution

The Correct Option is D

Solution and Explanation

Idea: Match each choice against the real DOM interface.

A DOM element has a property called $style$ that holds inline CSS. You set a single CSS field by writing $element.style.property = value$. For colour that is $element.style.color$.

Checking the choices: setStyle is not a DOM method, document.style.change does not exist, modifyStyle is not real. Only the assignment form is valid JavaScript that changes the look of the element at runtime.

Correct call:
\[ \text{document.getElementById("element").style.color = "red";} \]
\[\boxed{\text{Option D}}\]
Was this answer helpful?
0