Home >Web Front-end >JS Tutorial >Getting started with the JavaScript fontsize method (displaying strings according to the specified size)_Basic knowledge
JavaScript fontsize method
Thefontsize method returns a string defining the font size using the size attribute in the HTML font tag. Its syntax is as follows:
Parameter description:
Parameters | Description | ||||||
---|---|---|---|---|---|---|---|
str_object | String (object) to be operated on | ||||||
size | Required. Numbers from 1 to 7, the larger the number, the larger the font. The font size comparison is as follows:
3:16px 4:18px5:24px 6:32px 7:48px |
Tip: This method does not comply with ECMA standards and is not recommended.
fontsize method instance
Run this example, output:
www.jb51.net
Tip: This method returns the string defined using the HTML font size tag, even though this method cannot dynamically change the font size. If you want to dynamically change the font size of an element, you can refer to the following example:
function changFont( x ){
Document.getElementById("article").style.fontSize = x;
}
In this example, the size of the font (id="article") can be dynamically changed by controlling the font CSS style through JavaScript.