JavaScript – Change the font size of a Element
In this post we will give you information about JavaScript – Change the font size of a Element. Hear we will give you detail about JavaScript – Change the font size of a ElementAnd how to use it also give you demo for it if it is necessary.
we are going to learn about how to change the font size of a html element using JavaScript.
Consider, that we have the following p element in our HTML:
<p >Random text goes here</p>
Now, we want to change the above element size using JavaScript.
Changing the font size
To change the font size of a element, first we need to access the element object inside the JavaScript using the document.getElementByClassName() method.
const el = document.getElementByClassName("content");
Now, set its style.fontSize property to your desired size (eg: 10px or 20px, etc).
el.style.fontSize = "20px";
It changes the font size of a element to 20px.
Full example:
<p >Random text goes here</p>
JavaScript:
const el = document.getElementByClassName("content");el.style.fontSize = "20px"; // changes the font size
Hope this code and post will helped you for implement JavaScript – Change the font size of a Element. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs