Link to home
Start Free TrialLog in
Avatar of rypinbubs
rypinbubs

asked on

Simple javascript not working in Firefox

Can anybody tell me why this simple example works fine in IE, Chrome, Safari, and Opera but not in FireFox?

Thanks!

HTML:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication8.WebForm1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body id="body">
<script type="text/javascript">
    function setHover(id, color) {
       if(id != "") {
         var buttonName = document.getElementById(id.id);
         buttonName.style.backgroundColor = color;
        }
    }
 </script>
    <form id="form1" runat="server">
    <div id ="test">
        <asp:Button ID="Button1" runat="server" Text="Button" />
    </div>
    </form>
</body>
</html>

Open in new window


CodeBehind
public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Button1.Attributes.Add("onmouseover", "setHover(window.event.srcElement, 'Red');");
        }
    }

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of kaufmed
kaufmed
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
i agree with kaufmed, this is a job for css not javascript.
Avatar of rypinbubs
rypinbubs

ASKER

I agree with kaufmed too, but unfortunately this is just a small part of a bigger problem.
Thanks for the help guys!