www.webdeveloper.com
Recent Articles
  • Finding Slow Running Queries in ASE 15
  • A More Advanced Pie Chart for Analysis Services Data
  • Adobe AIR Programming Unleashed: Working with Windows
  • Performance Testing SQL Server 2008's Change Data Capture Functionality
  • The ABC's of PHP: Introduction to PHP
  • How to Migrate from BasicFiles to SecureFiles Storage
  • Why the Twitter Haters Are Wrong
  • User Personalization with PHP: Beginning the Application
  • Whats in an Oracle Schema?
  • Lighting Enhancement in Photoshop
  •  

    Go Back   WebDeveloper.com > Client-Side Development > JavaScript

    JavaScript JavaScript (not Java) Discussion and technical support, including AJAX and frameworks (JQuery, MooTools, Prototype...)

    Reply
     
    Thread Tools Search this Thread Rate Thread Display Modes
      #1  
    Old 07-18-2008, 10:32 PM
    ian0411 ian0411 is offline
    Registered User
     
    Join Date: Jul 2008
    Posts: 4
    resolved [RESOLVED] Help need! How to use Javascript to change font size & color?

    Hi All,

    I am new to the website design world. I really love it. But I have a problem about how to link my web page to a separate .js file.

    In my web page, I have 5 links. The problem I have is to use Javascript to make a rollover type of effect. I want to change fonts to 14px and blue color when the mouse hovers. And change it back when the mouse out.

    Here are my codes in the web page:
    --------------------------------------------------------------------
    <li><a href="home.aspx" title="home">home</a></li>
    <li><a href="contactinfo.aspx" title="contactinfo">contactinfo</a></li>
    <li><a href="customerservice.aspx" title="customerservice">customerservice</a></li>
    <li><a href="feedback.aspx" title="feedback">feedback</a></li>
    <li><a href="myaccount.aspx" title="myaccount">myaccount</a></li>
    ---------------------------------------------------------------------

    Can anyone show me how to write a Javascript code into a separate file and make this work? I really appreciate your help.

    Thanks,

    Ian
    Reply With Quote
      #2  
    Old 07-19-2008, 01:30 AM
    Fang's Avatar
    Fang Fang is offline
    Resistance is futile
     
    Join Date: Apr 2003
    Location: Netherlands
    Posts: 17,251
    Use css:
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html lang="en">
    <head>
    <title>rollover</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    
    <style type="text/css">
    ul {width:10em;}
    a {	
    display:block;
    font-family:Verdana, Geneva, Arial, Helvetica, sans-serif;
    font-size:0.8em;
    color:#000;
    background:#ccc;
    } 
    a:hover {
    font-size:1em;
    color:#00f;
    background:#ff9;
    }
    </style>
    
    </head>
    <body>
    <ul>
    <li><a href="home.aspx" title="home">home</a></li>
    <li><a href="contactinfo.aspx" title="contactinfo">contactinfo</a></li>
    <li><a href="customerservice.aspx" title="customerservice">customerservice</a></li>
    <li><a href="feedback.aspx" title="feedback">feedback</a></li>
    <li><a href="myaccount.aspx" title="myaccount">myaccount</a></li>
    </ul>
    </body>
    </html>
    __________________
    At least 98% of internet users' DNA is identical to that of chimpanzees
    Reply With Quote
      #3  
    Old 07-19-2008, 01:32 AM
    mathursrishti's Avatar
    mathursrishti mathursrishti is offline
    Registered User
     
    Join Date: Jul 2008
    Posts: 30
    No javascript required, just simple css

    <style type="text/css">

    .blueHover a:link
    {
    text-decoration: underline; color: black;
    }

    .blueHover a:hover
    {
    text-decoration: underline; color: blue;
    font-size:14px;
    }

    </style>

    --------------------------------------------------------------------
    <li><a href="home.aspx" title="home" class="blueHover">home</a></li>
    ---------------------------------------------------------------------
    Reply With Quote
      #4  
    Old 07-19-2008, 09:30 AM
    ian0411 ian0411 is offline
    Registered User
     
    Join Date: Jul 2008
    Posts: 4
    Thanks Fang and mathursrishti. However, I want to learn how to use Javascript to make it happen. Maybe this is kind of stupid not to take the advantage of CSS. Do you guys can help me with that? I need to create a separate sheet to store Javascript and write some codes in HTML to read the code.

    Thanks again,

    Ian
    Reply With Quote
      #5  
    Old 07-19-2008, 03:01 PM
    ian0411 ian0411 is offline
    Registered User
     
    Join Date: Jul 2008
    Posts: 4
    Please, can anyone show me how to use JavaScript to do this trick? I really appreciate your kindness.

    Thanks,

    Ian
    Reply With Quote
      #6  
    Old 07-19-2008, 07:20 PM
    felgall's Avatar
    felgall felgall is offline
    Computer Consultant
     
    Join Date: Mar 2005
    Location: Sydney, Australia
    Posts: 7,979
    It is completely inappropriate to do something with JavaScript that should be done with CSS. If you were to do this with JavaScript then you'd need code to update the CSS for the "blueHover" class to the exact values that could have been entered into the CSS directly in the first place. You'd only really need to9 do that if you want visitors to be able to select between different actions on hovering over things based on a previous action and if you want that then a stylesheet switcher would be a more appropriate way of achieving it since almost all browsers have a stylesheet switcher built in and so you really only need to create a JavaScript equivalent for your visitors using Internet Explorer.
    Reply With Quote
      #7  
    Old 07-19-2008, 08:45 PM
    Declan1991 Declan1991 is offline
    Moderator
     
    Join Date: Aug 2007
    Posts: 2,699
    Unless it is a homework assignment? We don't do them for people.
    __________________
    If I have helped
    Quote:
    Great wit and madness are near allied, and fine a line their bounds divide.
    Reply With Quote
      #8  
    Old 07-19-2008, 10:51 PM
    ian0411 ian0411 is offline
    Registered User
     
    Join Date: Jul 2008
    Posts: 4
    I searched everywhere for text change by using JavaScript but no help. CSS maybe a better resolution for me at this time I guess. Thanks all for the help.
    Reply With Quote
      #9  
    Old 07-20-2008, 02:30 AM
    Fang's Avatar
    Fang Fang is offline
    Resistance is futile
     
    Join Date: Apr 2003
    Location: Netherlands
    Posts: 17,251
    The usual method is to swap classes:
    Code:
    <li><a href="home.aspx" onmouseover="this.className='highlight';"  onmouseout="this.className='normal';" title="home">home</a></li>
    __________________
    At least 98% of internet users' DNA is identical to that of chimpanzees
    Reply With Quote
    Reply

    Bookmarks


    Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
     
    Thread Tools Search this Thread
    Search this Thread:

    Advanced Search
    Display Modes Rate This Thread
    Rate This Thread:

    Posting Rules
    You may not post new threads
    You may not post replies
    You may not post attachments
    You may not edit your posts

    BB code is On
    Smilies are On
    [IMG] code is Off
    HTML code is Off
    Forum Jump


    All times are GMT -5. The time now is 04:20 AM.



    Acceptable Use Policy

    internet.comMediabistrojusttechjobs.comGraphics.com

    WebMediaBrands Corporate Info


    Advertise | Newsletters | Feedback | Submit News

    Legal Notices | Licensing | Permissions | Privacy Policy

    Powered by vBulletin® Version 3.7.3
    Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.