Javascript change button font color

Byadmin

Oct 26, 2014

Last updated on November 17th, 2015 at 05:33 am

VN:F [1.9.22_1171]
Rating: 2.5/10 (2 votes cast)

In this tutorial you will see using javascript change button font color. Javascript setTimeout is very handy when we need to call functions within a definite time interval. In the below example script i am using setTimeout and implemented a simple logic to call 2 different javascript functions with a time interval of 2 seconds [2000ms]. The function will change the font color automatically after 2 seconds. This can also be used to call functions infinite times.

Script is very simple, When you click on the button it changes color of the font inside button from red to black and black to red.

<script type="text/javascript">
function setToRed()
{
document.getElementById("colourButton").style.color = "red"
setTimeout ( "setToBlack()", 2000 );
}
function setToBlack()
{
document.getElementById("colourButton").style.color = "black"
setTimeout ( "setToRed()", 2000 );
}
</script>
<input type="button" name="clickMe" id="colourButton" value="Click me and wait!" onclick="setToRed()"/>

You can also use settimeout inside an web page to call ajax function multiple times.

VN:F [1.9.22_1171]
Rating: 2.5/10 (2 votes cast)

Leave a Reply

Your email address will not be published. Required fields are marked *

sixteen − 8 =