Solved

javascript for onmouseover, onmouseout for a <A>

Posted on 2006-10-21
2
758 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

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
how can i remove string values 2 29
Javasctipt 2 25
Getting selected value of a dropdown with jquery 7 35
Writing comments on <p></P> or paragraph 2 12
When you need to keep track of a simple list of numbers or strings, the Array object is your most direct tool.  As we saw in my earlier EE Article (http://www.experts-exchange.com/A_3488.html), typical array handling might look like this: (CODE) B…
In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
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…

776 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