Solved

javascript for onmouseover, onmouseout for a <A>

Posted on 2006-10-21
2
761 Views
Last Modified: 2012-05-05
Hi!

Here's the code I have:

-->
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <script language="javascript" type="text/javascript">  
    function HyperlinkStyle1OnMouseOver(obj, strobj)
    {
        var clr = "#cc9900";
        var td = "none";
        var bc = "#F0F0F0";
        var str = "<a id=\"" + strobj + "\" style='background-color:" + bc + "; color:" + clr + "; text-decoration:" + td + ";' onmouseover=\"javascript:HyperlinkStyle1OnMouseOver(" + strobj + ",'" + strobj + "');\" onmouseout=\"javascript:HyperlinkStyle1OnMouseOut(" + strobj + ",'" + strobj + "');\" href='Default.aspx'>Admin</a>";
        obj.outerHTML = str;
    }
    function HyperlinkStyle1OnMouseOut(obj, strobj)
    {
        var clr = "#608888";
        var td = "underline";
        var bc = "white";
        var str = "<a id=\"" + strobj + "\" style='background-color:" + bc + "; color:" + clr + "; text-decoration:" + td + ";' onmouseover=\"javascript:HyperlinkStyle1OnMouseOver(" + strobj + ",'" + strobj + "');\" onmouseout=\"javascript:HyperlinkStyle1OnMouseOut(" + strobj + ",'" + strobj + "');\" href='Default.aspx'>Admin</a>";
        obj.outerHTML = str;
        alert(obj.outerHTML);
    }    
    </script>
</head>
<body>
<a id='span6' style="color: #608888" onmouseover="javascript:HyperlinkStyle1OnMouseOver(span6,'span6');" onmouseout="javascript:HyperlinkStyle1OnMouseOut(span6,'span6');" href="Default.aspx">Admin</a></p>
</body>
</html>
-->

When the mouse is over the hyperlink, the style changes. However, when the mouse moves out, the style doesnt revert back. the Alert() in the OnMouseOut() code never gets called. Can someone help me in figuring out what I'm doing wrong?

Thanks,
Mustansir
0
Comment
Question by:muskad202
  • 2
2 Comments
 
LVL 41

Accepted Solution

by:
HonorGod earned 25 total points
ID: 17780126
 You've made it too hard.  Try something easier, like:
----------------------------------------------------------------
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<style type="text/css">
.normal {
    color            : #608888;
      background-color : white;
    text-decoration  : none;
}
.special {
    color            : #F0F0F0;
      background-color : white;
    text-decoration  : underline;
}
</style>

<script type="text/javascript">  
    function Over( obj )
    {
      obj.className = 'special';
    }
    function Out( obj )
    {
      obj.className = 'normal';
      alert( 'out()' );
    }    
    </script>
</head>
<body>
<a id='span6' class='normal' onmouseover='Over(this);' onmouseout='Out(this);' href='Default.aspx'>Admin</a>
</body>
</html>
0
 
LVL 41

Expert Comment

by:HonorGod
ID: 17781618
Thanks for the 'A'
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

837 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question