I have button in td, I want to change the backcolor of button when the mouse move over it ..

As we change the backcolor of td, when we moves move over it.Eg Below-

<td  onMouseOver="this.bgColor='#00CC00'" onMouseOut="this.bgColor='#009900'" bgColor=#009900 style="width: 33px; height: 81px">
                                </td>

Recommended Answers

All 4 Replies

you can do that with javascript, post it to javascript forum. if your button is a server control then you need its clientID to change its background color. Or if you have a specific place for the button in the TD, you can access it using the html node tree, e.g. the childNodes of the TD node. I am sorry that i am too busy to provide the sample code now.

I know this could be done in CSS easily if your interested?

Hi,
You can do it using javascript and css.
Try this code it might help.


<head runat="server">
<title>Untitled Page</title>
<style type="text/css" runat="server">
.cs
{
background-color:Window;
}
.cs1
{
background-color:ButtonFace;
}
</style>
<script type="text/javascript">
function mov()
{
var btnid= document.getElementById('btn1');
btnid.className='cs';
}
function mout()
{
var btnid= document.getElementById('btn1');
btnid.className='cs1';
}
</script>
</head>
<body>
<form id="form1" runat="server">

<input type="button" id="btn1" value="Change" onmouseover="mov()" onmouseout="mout()" runat="server" onserverclick="clk" />
</form>

hi praveen your code work correctly,But its lengthy...But thx

Other Way of Doing it -

protected void Page_Load(object sender, EventArgs e)
    {
        //Button1.Attributes.Add("onmouseover", "this.style.backgroundColor='Silver'");
        //Button1.Attributes.Add("onmouseout", "this.style.backgroundColor='green'");


OR

        //Button1.Attributes.Add("onmouseover", "this.style.backgroundColor='#009900'");
        //Button1.Attributes.Add("onmouseout", "this.style.backgroundColor='#000000'");
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.