Web Analytics Made Easy -
StatCounter Mouse Over and Out doesnt want to work. - CodingForum

Announcement

Collapse
No announcement yet.

Mouse Over and Out doesnt want to work.

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Mouse Over and Out doesnt want to work.

    The script below does change the link colors onmouseover and onmouseout:

    <script name="javascript">
    function overAndOut(oEl) {
    if (oEl.style.color == 'orange')
    oEl.style.color = 'blue';
    else oEl.style.color = 'orange';
    }
    </script>



    <a href="myfile.htm" onmouseover="overAndOut(this);"
    onmouseout="overAndOut(this);">LINK CHANGES COLORS OKAY HERE</a>



    But if I put the other stuff with the onmouseover and onmouseout the text doesnt change colors. Is it something to do with the "this" part or anythingelse someone could see that I am missing?

    <a href="myfile.htm"
    onMouseOver="javascript:window.status='MyText...';return true;overAndOut(this);"
    onMouseOut="javascript:window.status='';return true;overAndOut(this);">
    CHANGE LINK TEXT COLOR ON MOUSE OVER HERE</a>

  • #2
    edit: Disabled Smiles
    Switch the functions like this:

    Code:
    onMouseOver="javascript:overAndOut(this);window.status='MyText...';return true;" 
    onMouseOut="javascript:overAndOut(this);window.status='';return true;">
    also you can get the overAndOut affect without the script by adding this in your head tag and remove the overandout:

    Code:
    <style>
       A:link { color: blue ;}
       A:visited {color: blue ;}
       A:active { color: blue;}
       A:hover {color: orange;}
    </style>
    USA

    Comment


    • #3
      Code:
      <a href="myfile.htm" 
      onMouseOver="javascript:window.status='MyText...';return true;overAndOut(this);" 
      onMouseOut="javascript:window.status='';return true;overAndOut(this);"> 
      CHANGE LINK TEXT COLOR ON MOUSE OVER HERE</a>
      Seems to me that "return true" is doing just what it says; and the overandOut() function isn't being executed.

      Comment


      • #4
        <html>
        <head>
        <style type="text/css">

        .over {
        color: orange;
        }

        .out {
        color: blue;
        }

        </style>
        <script type="text/javascript">

        var stat = new Array();
        stat[0] = 'Status message zero.';
        stat[1] = 'Status message one.';

        function overAndOut(el, classname, statMsg) {
        if (typeof el.className != 'undefined')
        el.className = classname;
        status = statMsg;
        return true;
        }

        </script>
        </head>
        <body>

        <a href="myfile.htm" class="out"
        onmouseover="return overAndOut(this,'over',stat[0])"
        onmouseout="return overAndOut(this,'out','')">LINK CHANGES COLORS OKAY HERE</a><br><br>
        <a href="myfile.htm" class="out"
        onmouseover="return overAndOut(this,'over',stat[1])"
        onmouseout="return overAndOut(this,'out','')">LINK CHANGES COLORS OKAY HERE</a>

        </body>
        </html>

        Generally a better idea to swap classes; this allows you to easily modify the style changes. If you don't want to create a pile of 'use once and discard' functions, extract the page-specific data from them and pass it in as parameters. Watch those return statements - HTML event handlers (onmouseover, e.g.) are wrapped in functions, and return ends their execution.

        Comment


        • #5
          Swap classes like this:

          Code:
          <html> 
          <head> 
          <style type="text/css"> 
          
          .over { 
          color: orange; 
          } 
          
          .out { 
          color: blue; 
          } 
          
          </style> 
          </head>
          <body>
          <a href="fileName.htm" class="out" onMouseover="this.className='over'; return true" onMouseout="this.className='out'; return true">.........</a>
          </body>
          </html>
          Scripting | JavaScripts | PerlScripts | Python Scripts | Articles | My Journal

          Comment

          Working...
          X