iLTC Home
Bookmark iLTC!

Categories

Perl
  • Perl Tutorials Beginners

  • Javascript
  • Javascript Tutorials
  • Javascript Tutorials Beginners

  • HTML
  • HTML Tutorials

  • Command Line
  • Command Line Tutorials

  • How Tos
  • Other Tips and Tricks



  • <script type='text/javascript'>
    2210812

    iLoveTheCode.com

    Javascript Change Font Size

    <p id=hey>This is my fabulous text that will change.</p>

    <a onMouseover=document.getElementById('hey').style.fontSize='10'> Make it Tiny!</a> ----
    <a onMouseover=document.getElementById('hey').style.fontSize='24'> Make it HUGE!!!</a>


    -In our HTML paragraph tag, we name our id attribute hey because we like the name.
    -We create two links that use the Javascript onMouseover event handler.
    ---After the equals sign:
    -----document - this page
    -----getElementById - Javascript's built-in method that will get elements from our page.
    -----In the parenthesis - we state that we will be working on the hey element of our page.
    -----We then call the Javascript style object.
    -----We then call the fontSize property of the style object.
    -----We say make it 10 pixels for the first sentence and 24 pixels for the second.


    Now, to make fonts get bigger or smaller, we'll write a function. But first, we'll make a few changes to our text in our anchor tags using onClick to call our new function.


    <p id=hey>This is my fabulous text that will change.</p>

    <a onClick=funTime("grow")> GROW!</a> ----
    <a onClick=funTime()> Make it Smaller!</a>

    <script type="text/javascript">
    var dsi=16;
    function funTime(p) {
    if (p == "grow") {
    dsi++;
    }
    else {
    dsi--;
    }
    document.getElementById('hey').style.fontSize=dsi;
    }
    </script>


    Our first two sections are pretty much the same except we call our new function with an onClick event handler.
    ---We pass the value of "grow" if the GROW text is clicked.

    The script:
    -We name a var dsi and give it value of 16.
    -We name our function funTime and say whatever is passed to it from our page will be stored in a variable we name p.
    -We say if p equals grow, increment (add one to) our variable dsi.
    -Or else if p is not equal to grow, decrement (subtract one from) our variable dsi.

    Then we use our same snippet of code from earlier, just changing the part after the equals sign to have the value of our variable dsi. dsi starts at 16 and gets bigger or smaller depending on which text a user clicks.


    Here's my Javascript Change Fonts article, which has even more fun things to do with fonts.


    Free Copy and Paste Javascript Code:

    <script type="text/javascript">
    <!--

    var dsi=16;
    function funTime(p) {
    if (p == "grow") {
    dsi++;
    }
    else {
    dsi--;
    }
    document.getElementById('hey').style.fontSize=dsi;
    }

    -->
    </script>

    <table height=50><tr><td valign=top height=50>
    <p id=hey>This is my fabulous text that will change.</p>
    </td></tr></table>

    <a onClick=funTime("grow")> GROW!</a> ----
    <a onClick=funTime()> Make it Smaller!</a>

    <br><br><br>

    <a id=bop>Hello</a>
    <a onMouseover=document.getElementById('bop').style.fontSize='10'> Make it Tiny!</a> ----
    <a onMouseover=document.getElementById('bop').style.fontSize='24'> Make it HUGE!!!</a>



    For fun, I just wrapped this article in a <div> tag and gave it my id name. You could do the same in the body tag. SO...

    GROW this page! ---- Make it Smaller!


    Resources:
    Javascript Change Fonts
    Javascript Change Background Colors
    HTML paragraph tag
    Javascript onMouseover
    Javascript onClick
    If, Else If, and Else in Javascript
    Create a Function in Javascript
    Call your Function in Javascript
    Passing an Argument or Variable to a Javascript
    Increment a Variable in Javascript






    Previous Article: Javascript Change Fonts
    Next Article: Javascript Change Background Colors






    Search iLTC w/ Google




    Recent Articles

  • HTML Font Code
  • Javascript and CSS - Easy Pop Up Help Balloons
  • Use OnMouseOver in Javascript
  • Use onMouseOut in Javascript
  • Use innerHTML to Change Text on a Page
  • Renaming a File with Perl's RENAME Function
  • PRINT to Browser with document.write Command in Javascript
  • Passing an Argument or Variable to a Javascript
  • Opening an Alert Box in Javascript
  • Opening a REMOTE WINDOW in Javascript
  • OPEN and WRITE a Data File in Perl
  • OPEN and READ a Data File in Perl
  • Mimic Typing from a Textfield in a Textarea with Javascript
  • Javascript Reset Form








  • Perl Programming - Javascript Programming - HTML Code - Mac Unix Command Line - Maybe Some PHP - Free Scripts - ILoveTheCode
    All Content © 2006-2009 iLoveTheCode.com


    Contact Chris | About this Site


    2210024
    Counter by iLoveTheCode.com


    Last Modified: Saturday, 10-Jan-2009 05:40:24 EST



    Hosted as well :)
    Home-brewed logo - 1997