How to change font in JavaScript?

To change font in JavaScript, do this: element.style.fontFamily = 'Courier'.

For example, if this is your element:

<div id="my-element">text</div>

Then you can change the font like so:

document.getElementById('my-element').style.fontFamily = 'Courier';

And you can do the same with the style attribute in HTML:

<div id="my-element" style="font-family: Courier">text</div>