JavaScript fontsize method
The fontsize method returns a string that defines the font size using the size attribute in the HTML font tag. The syntax is as follows:
The code copy is as follows:
str_object.fontsize( size )
Parameter description:
| parameter | illustrate |
|---|---|
| str_object | String (object) to operate |
| size | Required. The larger the number, the larger the font, the larger the font size, the font size is as follows: 1:10px 2:14px 3:16px 4:18px 5:24px 6:32px 7:48px |
Tip: This method does not comply with ECMA standards and is not recommended for use.
fontsize method example
<script language="JavaScript">
var str = "www.VeVB.COM";
document.write( str.fontsize( 7 ) );
</script>
Run this example and output:
The code copy is as follows:
www.VeVB.COM
Tip: This method returns a string defined using the HTML font size tag, that is, using this method cannot dynamically change the font size. If you want to dynamically change the font size of the element, you can refer to the following example:
Further reading: Change the font color of page elements
The code copy is as follows:
<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'm some text...<br />
Some Text ...
</p>
</body>
</html>
In this example, the size of the font (id="article") can be dynamically changed through JavaScript.