www.webdeveloper.com
Results 1 to 6 of 6

Thread: [RESOLVED] Change Font Size

  1. #1
    Join Date
    Apr 2005
    Posts
    4

    resolved [RESOLVED] Change Font Size

    I have a font tag I am trying to change the size of. The tag is simply this:

    [tt]<font size="5">Text that's too big</font>[/tt]

    I can't change the tag so I am using the following code to try and modify it but to no avail:

    Code:
    <script type="text/javascript">
    //<!--
    
    var title = document.getElementsByTagName('font');
    if (title.size == '5') {
        title.style.fontsize = '12pt';
    }
    //-->
    </script>

  2. #2
    Join Date
    Nov 2010
    Posts
    1,085
    getelementsbytagname returns a collection (kind of like an array) so it is best to loop through it, even if you know it is only one element.

    also, when converting css tags that have a hyphen into DOM commands (I have no idea if I have the terminology right here, but bear with me) they generally become camel case, so font-size becomes fontSize. try this:

    Code:
    <!html>
    <head>
    </head>
    <body>
    <font size="5">Text that's too big</font>
    <input type="button"  value="click me!" onclick="changeSize()">
    <script type="text/javascript">
    
    function changeSize(){
    var title = document.getElementsByTagName('font');
    for(i=0;i<title.length;i++){
    if (title[i].size == '5') {
        title[i].style.fontSize = '12pt';
        }
    }
    }
    </script>
    </body>
    </html>

  3. #3
    Join Date
    Dec 2011
    Location
    Centurion, South Africa
    Posts
    795
    What's a <font> tag?

  4. #4
    Join Date
    Apr 2005
    Posts
    4
    Thank you for the new code. But I need it to automatically resize the font onpageload instead of via a button.

  5. #5
    Join Date
    Apr 2005
    Posts
    4
    And a <font> tag is a basic format tag in HTML. You can add in in a variety of variables and values (just to include a few):

    <font color="#090909" size="12pt" family="Times New Romans"> </font>

    For more information I would suggest visiting W3Schools and going through their HTML tutorial section. I hope this helped.

  6. #6
    Join Date
    Apr 2005
    Posts
    4
    Nevermind I got it to work window.onload = functionname;

    Can a mod or admin please mark this as done. It won't let me edit my posts even though it says I may down at the bottom.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles