SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict
    Join Date
    Feb 2009
    Location
    israel
    Posts
    218
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Can anyone help me change font size ?

    Hi everyone,
    I use (try to use that is) java script to chang font size. The following code loads a page with fonts of initial size of: 40px as defined in the <p> element. The "onclick" property of that element activates a javascript function "function1". That function matches a style with a class selector named: "newSize". That style contains a style of font size of 16px.
    Code:
    <html>
    <head>
      <title>change font size</title>
      <style type="text/css">
        .newSize 
            { 
             font-size:16px;
            }
      </style>
      <script type="text/javascript">
      <!--
        function function1() 
        {
        document.getElementById("myP").className = "newSize"
        }
      -->
    </script>
    </head>
    
    <body>
    <p id="myP" 
       style="font-size:40px;"
       onclick="function1()">
       abc
    </p>
    </body>
    </html>
    When the page is loaded and i click the text nothing happens. Anyone knows why ?
    Thanks.

  2. #2
    SitePoint Wizard silver trophy rushiku's Avatar
    Join Date
    Dec 2003
    Location
    A van down by the river
    Posts
    2,056
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)
    This should actually be in the JavaScript forum...

    Your manually set font-size in myP takes precedence over the class change. Just write another class and set the initial font-size there, then you'll be swapping apples for apples when you change the className. (and it will work)

  3. #3
    SitePoint Addict
    Join Date
    Feb 2009
    Location
    israel
    Posts
    218
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks a lot !
    I took jsp for Java Script Programming. Apparently i was wrong, next time i'll be more careful.


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
  •