JavaScript -Change CSS Color For 5 Seconds
Solution 1:
try this:
function highlight(obj){
var orig = obj.style.color;
obj.style.color = " #f00'<="" span="">;
setTimeout(function(){
obj.style.color = orig;
}, 5000);
}
and in the html:
<a href="#faq1" onClick="highlight(document.getElementById('faq1'));">
this function will work for any object you pass to it :-)
Solution 1:
try this:
function highlight(obj){
var orig = obj.style.color;
obj.style.color = " #f00'<="" span="">here is a working fiddle: http://jsfiddle.net/maniator/dG2ks/
Solution 2:
You can use window.setTimeout()
<a href="#faq1" onClick="highlight()">
<script type="text/javascript">
function highlight() {
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:
<a id="faqLink" href="#faq1">FAQ Link</a>
<script type="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:
<script type='text/javascript'>
function changeColor(element, color){
document.getElementById(element).style.color = color
setTimeout(function(){ changeColor(element, '#000') }, 5000)
}
</script>
Some HTML:
<a href="#faq1" onClick="changeColor('faq1', '#f00')">
Post a Comment for "JavaScript -Change CSS Color For 5 Seconds"