Simple javascript not working in Firefox

rypinbubs used Ask the Experts™
Can anybody tell me why this simple example works fine in IE, Chrome, Safari, and Opera but not in FireFox?


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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

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

Open in new window

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

Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Glanced up at my screen and thought I had coded the Matrix...  Turns out, I just fell asleep on the keyboard.
Most Valuable Expert 2011
Top Expert 2015
As far as I can read, FF doesn't use window.event. There is discussion of this here. However, why use Javascript just to change the backcolor of something? Why wouldn't you use the CSS pseudo-class :hover?
You can try this one
Button1.Attributes.Add("onmouseover", "setHover(this, 'Red');")

"this" will pass the current button and you can get the id in javascript code.
i agree with kaufmed, this is a job for css not javascript.


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

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial