Javascript -change Css Color For 5 Seconds
I am trying to make a way of briefly highlighting the text on named links - but only for a few seconds.
Solution 1:
try this:
functionhighlight(obj){
var orig = obj.style.color;
obj.style.color = '#f00';
setTimeout(function(){
obj.style.color = orig;
}, 5000);
}
and in the html:
<ahref="#faq1"onClick="highlight(document.getElementById('faq1'));">
this function will work for any object you pass to it :-)
here is a working fiddle: http://jsfiddle.net/maniator/dG2ks/
Solution 2:
You can use window.setTimeout()
<ahref="#faq1"onClick="highlight()"><scripttype="text/javascript">functionhighlight() {
var el = document.getElementById('faq1');
var original = el.style.color;
el.style.color='#f00';
window.setTimeout(function() { el.style.color = original; }, 5000);
}
</script>
Solution 3:
Write a function to change it back (by setting the same property to an empty string). Run it using setTimeout
Solution 4:
Try this:
<aid="faqLink"href="#faq1">FAQ Link</a><scripttype="text/javascript">document.getElementById('faqLink').onclick = function(e){
e = e || window.event;
var srcEl = e.target || e.srcElement;
var src = document.getElementById("faq1");
var prevColor = src.style.color;
src.style.color = '#f00';
setTimeout(function(){
src.style.color = prevColor;
}, 5000); //5 seconds
}
</script>
Solution 5:
Some JS:
<scripttype='text/javascript'>functionchangeColor(element, color){
document.getElementById(element).style.color = color
setTimeout(function(){ changeColor(element, '#000') }, 5000)
}
</script>
Some HTML:
<ahref="#faq1"onClick="changeColor('faq1', '#f00')">
Post a Comment for "Javascript -change Css Color For 5 Seconds"