Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
Comments on Change font-family with JavaScript
Parent
Change font-family with JavaScript
I want to change the font-family
of all elements in a document with JavaScript.
I have tried this:
document.querySelectorAll("body").forEach( (e)=>{
e.style.fontFamily = "arial";
});
This changed the font-family of generally everything besides what already had a font-family
defined in CSS ID or class.
How could I make the JavaScript command to "run through" these IDs and classes?
Post
The following users marked this post as Works for me:
User | Comment | Date |
---|---|---|
user36363 | (no comment) | Nov 12, 2021 at 03:34 |
Without knowing your use case, the simplest modification would just be to target everything:
document.querySelectorAll("*").forEach((e) => {
e.style.fontFamily = "arial";
});
(As an aside, if you want to target the body element, just use document.body
. No need for selectors.)
0 comment threads