2

While I was changing heading font size on DevTool, I noticed that I couldn't use

heading.style.font-size = '2em';

but instead I had to use

heading.style.fontSize = '2em';

Why is that?

Jesse
  • 3,522
  • 6
  • 25
  • 40
Fariman Kashani
  • 856
  • 1
  • 16
  • 29

1 Answers1

8

Dashes cannot be used in dot notation because property names are identifiers. The - is a keyword for things such as subtraction.

You can however do the following.

document.querySelector("div").style["font-size"] = "7em";
<div>Test</div>
DTavaszi
  • 192
  • 1
  • 10
Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335