Mahogany
Mahogany

Reputation: 529

How can I temporarily change the colour of some text?

I have a button that updates a Kendo UI Grid, all works fine. However I want to have some white text above the button that says "Changes saved" or something, not important.

How can I temporarily change the colour of some text?

I've looked into using setTimeout() but it seems like that executes a function after a set period of time, not for a set period of time. I know how to actually change the colour, using

document.getElementById("foo").style.color = "#ff0000";

Upvotes: 1

Views: 748

Answers (2)

imvain2
imvain2

Reputation: 15847

You can still use setTimeout, just use it to change the color back

document.getElementById("foo").style.color = "#ffff00";

setTimeout(function(){
document.getElementById("foo").style.color = "#ff0000";
},1500);
<div id="foo">text</div>

Upvotes: 1

Mahogany
Mahogany

Reputation: 529

After realising that I'm stupid and missed an obvious way of doing this; this is how I did it.

var i = document.getElementById("alert");
i.style.color = "black";
setTimeout(function () { i.style.color = "white" }, 2000);

Upvotes: 5

Related Questions