JavaScript – Change the Font Family of HTML Element
To change the font family of a HTML Element using JavaScript, get reference to the element, and assign required font family value to the element.style.fontFamily
property.
In the following example, we will change the font family of HTML Element with id "myElement"
to "monospace"
, in JavaScript, using element.style.fontFamily
property.
example.html
ADVERTISEMENT
Conclusion
In this JavaScript Tutorial, we learned how to change the font family of a HTML Element using JavaScript.