---
title: "How to change style on an element?"  
description: "How to change style on an element?"  
author: "Anonymous User"  
published: 2011-05-18  
updated: 2020-09-16  
canonical: https://www.mindstick.com/interview/952/how-to-change-style-on-an-element  
category: "javascript"  
tags: ["javascript"]  
reading_time: 1 minute  

---

# How to change style on an element?

Between CSS and javascript is a weird symmetry. CSS style rules are layed on top of the DOM. The CSS property names like "font-weight" are transliterated into "myElement.style.fontWeight". The class of an element can be swapped out. For example: \
document.getElementById("myText").style.color = "green";\
document.getElementById("myText").style.fontSize = "20";\
-or-\
document.getElementById("myText").className = "regular";

## Answers

### Answer by Anonymous User

Between CSS and javascript is a weird symmetry. CSS style rules are layed on top of the DOM. The CSS property names like "font-weight" are transliterated into "myElement.style.fontWeight". The class of an element can be swapped out. For example: \
document.getElementById("myText").style.color = "green";\
document.getElementById("myText").style.fontSize = "20";\
-or-\
document.getElementById("myText").className = "regular";


---

Original Source: https://www.mindstick.com/interview/952/how-to-change-style-on-an-element

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
