Tuesday, August 12, 2008

Change fore color of control using Java Script

Many times we need to set the fore color or back color of controls (e.g. label, button etc).

This can be achieved using CSS (supposing all of you know that) also but we can also do it using Java Script.

This is a simple java script trick so you can use it with html controls as well as asp.net server controls.

Here is an example for doing this :

Code:

<a href=”contact.aspx” class=”mainMenuNormalStyle” onmouseover=”style.color=’#FFB537′;”

onmouseout=”style.color=’#6D6E71′”>CONTACT</a>
<a href=”contact.aspx” class=”mainMenuNormalStyle” onmouseover=”style.backgroundcolor=’#FFB537′;”

onmouseout=”style.backgroundcolor=’#6D6E71′”>CONTACT</a>
In the above code example i set the value of style collection’s color property on the “onmouseover” event and reversed on “onmouseout” event.

No comments: