Click here to Skip to main content
15,890,506 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
Hi,

I want to change the backcolor of a button control on MouseOver event of a button using Javascript.
Posted
Updated 12-May-13 18:34pm
v2
Comments
Sergey Alexandrovich Kryukov 13-May-13 0:36am    
Not a question. Just do it. What's the problem?
—SA
Rockstar_ 13-May-13 1:18am    
I have searched in the net , i get answers like, we have to add in the page load button.attributes.add(), But We can write the javascript function directly and can call on mouseover of a button. But what is the use of button.attributes.add("MouseOver","SomeJavascriptCode()")?

We have very good support from Google Inc. through www.google.com,you can make use of that.Further,you can change button on mouse hover using the css like:

CSS
#yourbuttonid:hover 
{
    background:#ff0000;
}


You can also refer to the link below

change behaviour of button on mouseover Like Background color, text color etc.
 
Share this answer
 
v2
javascript:
XML
<script type="text/javascript">
    function GetBackColor() {
        document.getElementById("testButton").setAttribute("style", "background-color:green");
    }

    function RemoveColor() {
        document.getElementById("testButton").removeAttribute("style");
    }
    </script>


button:
<input type="button" id="testButton" onmouseover="GetBackColor()" value="test" onmouseout="RemoveColor()"/>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900