1

I have a div with some text, I want to change its background color on "onmouseover" event, its working fine in Internet Explorer but not working at all in Firefox.

Please answer.

Every attempt would be respected.

Thanks in advance...

3
  • what have you tried? and your question says it's working in Firefox, but not Firfox??? Commented May 7, 2011 at 12:42
  • It works fine in firefox but doesn't work at all in firefox?? Please show us the code you are using. Commented May 7, 2011 at 12:42
  • please post your source code here so more optimal solution you will get Commented May 7, 2011 at 12:51

3 Answers 3

2

a Pure javascript solution for your problem tell if it works for you

<div onMouseOver="this.style.backgroundColor='#CCFF99';"
onMouseOut="this.style.backgroundColor='#FFFFFF';" ">

Hello Welcome Testing Bg color on MouseOver 
</div>

Demo

jsfiddle.net/577nc/1

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot, please try answer this thread also:stackoverflow.com/questions/5920979/…
1

The following code works in firefox:

       <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <style>
            #div_to_change_colour {
                background: rgb(255, 0, 0);
            }
        </style>
        <script type="text/javascript">
            function changeColor(objectPassedIn){
                objectPassedIn.style.background = '#CCC';
                objectPassedIn.style.width = '200px';
            }
        </script>
        <title></title>
    </head>
    <body>
        <div id="div_to_change_colour" onmouseover="changeColor(this)">
            text inside div
        </div>
</body>
</html>

The problem you may have been facing is if you set the divs background color with 'background-color'. The above code uses 'background' to set the divs color and this can then be overided with javascript.

Comments

1

want to change its background color on "onmouseover" event

also you can make it using the simple CSS without any javascript code:

.myDiv {
 background:#ffffff;
}
.myDiv:hover {
  background:#cccccc;
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.