Walkthrough of JavaScript FontSize Method (display string by specified size) _ Basics

Source: Internet
Author: User

JavaScript FontSize Method

The FontSize method returns a string that defines the font size using the Size property in the HTML font label. The syntax is as follows:

Copy Code code as follows:

Str_object.fontsize (size)

Parameter description:

Parameters Description
Str_object The string to manipulate (object)
Size Necessary. 1 to 7 of the number, the larger the number of fonts, font size comparison is as follows:
1:10px
2:14px
3:16px
4:18px
5:24px
6:32px
7:48px

Tip: This method does not conform to the ECMA standard and is not recommended for use.

FontSize Method Instance

<script language= "JavaScript" >

var str = "Www.jb51.net";
document.write (Str.fontsize (7));

</script>

Run the example and output:

Copy Code code as follows:

Www.jb51.net

Tip: This method returns the string defined using the HTML font size label, which means that using the method does not change the font size dynamically. If you want to dynamically change the font size of an element, refer to the following example:

Extended reading: Changing page element Font Color

Copy Code code as follows:

<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>

In this example, you can dynamically change the size of the font (id= "article") by using JavaScript to control how the font CSS style is styled.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.