JavaScript fontsize method entry instance (to display strings at the specified size)
- 2020-03-30 04:09:00
- OfStack
JavaScript fontsize method
The fontsize method returns a string that defines the fontsize using the size attribute in the HTML font tag. The syntax is as follows:
str_object.fontsize( size )
Parameter description:
parameter | instructions |
---|---|
str_object | String (object) to manipulate |
size | A necessity. 1 to 7 The larger the number, the larger the font size. The font size comparison is as follows: 1 : 10px 2 : 14px 3 : 16px 4 : 18px 5 : 24px 6 : 32px 7 : 48px |
Note: this method does not conform to ECMA standards and is not recommended.
Instance of the fontsize method
< Script language = "JavaScript" >
Var STR = "www.jb51.net";
Document.write (STR. Fontsize (7));
< / script>
Run the example and output:
www.jb51.net
Tip: this method returns a string defined using the HTML font size tag. This method does not dynamically change the font size. If you want to change the font size of an element dynamically, see the following example:
Read more: change the font color of page elements
<html>
<script language="JavaScript">
function changFont( x ){
document.getElementById("article").style.fontSize = x;
}
</script>
<body>
<p>
<a onClick="changFont(14);"> normal </a> <a onClick="changFont(20);"> large </a>
</p>
<p id="article">
I am some words ...<br />
Some Text ...
</p>
</body>
</html>
In this example, the size of the font (id="article") can be dynamically changed by the way JavaScript controls the CSS style of the font.