JQuery: code example for setting the font size and jquery font size

Source: Internet
Author: User

JQuery: code example for setting the font size and jquery font size

JQuery:
Setting the font size on a webpage is a common operation. The following describes how to implement this function through code examples.
The Code is as follows:

 

<! DOCTYPE html> 

 

The above Code meets our requirements to achieve the amplification and reduction of text content. The following describes the implementation process.
I. Code comments:
1. $ (function () {}). After the text structure is fully loaded, run the code in the function.
2. $ ("span"). click (function () {}), register the click event handler function for the span element.
3. var thisEle = $ ("# para" ).css ("font-size"), get the text font size under the para element with the id attribute value.
4. var textFontSize = parseFloat (thisEle, 10), convert the font size to a numeric value type.
5. var unit = thisEle. slice (-2): truncates the string, that is, the last two digits, that is, the unit (px ).
6. var cName = $ (this). attr ("class") to obtain the class attribute value of the currently clicked span element.
7. if (cName = "bigger") {textFontSize + = 2 ;}, if you click the zoom in button, the font is enlarged.
8. $ ("# para" ).css ("font-size", textFontSize + unit), set the font size.
Ii. Related reading:
1. For details about click events, see click events in jQuery.
2. For details about the css () function, see the css () method section of jQuery.
3. For the parseFloat () function, see section 1 of parseFloat () method in javascript.
4. For details about the slice () function, refer to slice () method 1 of the String object in javascript.
5. For more information about the attr () function, see the attr () method section of jQuery.

The original address is: http://www.softwhy.com/forum.php? Mod = viewthread & tid = 12398.

For more information, see: http://www.softwhy.com/jquery/

 

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.