Skip to content Skip to sidebar Skip to footer

Javascript -change Css Color For 5 Seconds

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"