Solved

javascript for onmouseover, onmouseout for a <A>

Posted on 2006-10-21
2
752 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
Comment Utility
 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
Comment Utility
Thanks for the 'A'
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
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…

743 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now