SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot
    Join Date
    Mar 2008
    Posts
    129
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How do you change font size dynamically?

    Hey all.

    I have an onmouseover/out that I want to use in order to change the font-size of a table cell. I can access the cells ID etc fine, but I don't know the syntax to be used for font-size since there is a hyphen in the name.

    I've run into this issue with other style attributes and there was a non-hyphen version that was to be used.

    I've tried document.getElementById("ID").style.font-size = "14pt";
    and document.getElementById("ID").style.fontsize = "14pt";

    but neither work.

    Can anyone enlighten me on what to use and if there is a "rule of thumb" when trying to change hyphenated attributes?

    Dean

  2. #2
    Function Curry'er JimmyP's Avatar
    Join Date
    Aug 2007
    Location
    Brighton, UK
    Posts
    2,006
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Should be "fontSize" (with a capital "S")

    I.e.

    Code JavaScript:
    document.getElementById("ID").style.fontSize = "14pt";

    When applying a style in JS remember the style attribute should be camelCased rather than hyphenated.
    James Padolsey
    末末末末末末末末末末末末末末末末末末末
    Awesome JavaScript Zoomer (demo here)
    'Ajaxy' - Ajax integration solution (demo here)

  3. #3
    SitePoint Zealot
    Join Date
    Mar 2008
    Posts
    129
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by JimmyPaddy View Post
    Should be "fontSize" (with a capital "S")

    I.e.

    Code JavaScript:
    document.getElementById("ID").style.fontSize = "14pt";
    Bang.

    That's also how I did it before, but forgot. Thanks.


Bookmarks

Posting Permissions

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