CSS Property Names in JavaScript
Hypen in Name or Not
CSS property names are hyphen separated, e.g. font-size
.
JavaScript property names are camelCase: e.g. fontSize
.
Here is a table of setting styles in CSS and in JavaScript:
CSS | JavaScript |
background-color | x.style.backgroundColor |
font-size | x.style.fontSize |
font-family | x.style.fontFamily |
How to Find the Exact CSS Property Name in JavaScript
A easy way to check style property is to use browser's JavaScript console name completion feature.
Type document.body.style.
then press Tab, it'll show a list.
γsee How to Use Browser Consoleγ
