Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8478461
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T18:45:09+00:00 2026-06-10T18:45:09+00:00

I have a problem. I wish to flash (or blink) text from yellow to

  • 0

I have a problem. I wish to flash (or blink) text from yellow to grey, but I would like the yellow text to remain displayed longer than the grey text.

The code that I have works for an equal duration for each color.

function flashtext(ele,col) {
var tmpColCheck = document.getElementById( ele ).style.color;

   if (tmpColCheck === 'grey') {
       document.getElementById( ele ).style.color = col;
   } else {
       document.getElementById( ele ).style.color = 'grey';
   }
 } 

setInterval(function() {
    flashtext('flashingtext','yellow');
}, 700 ); //set an interval timer up to repeat the function

Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T18:45:10+00:00Added an answer on June 10, 2026 at 6:45 pm

    You can use setTimeout:

    function flashtext(ele,col) {
        var tmpColCheck = document.getElementById( ele ).style.color,
            time;
        if (tmpColCheck === 'grey') {
            document.getElementById( ele ).style.color = col;
            time=1400;
        } else {
            document.getElementById( ele ).style.color = 'grey';
            time=700;
        }
        setTimeout(function(){flashtext('flashingtext','yellow')},time);
    }
    flashtext('flashingtext','yellow');
    

    DEMO: http://jsfiddle.net/EfpEP/

    Edit:

    But it can be improved a bit:

    function flashtext(ele,col) {
        var style = document.getElementById(ele).style;
        (function main(){
            var cond=style.color === 'grey';
            style.color=cond?col:'grey';
            setTimeout(main,cond?1400:700);
        })();
    }
    flashtext('flashingtext','yellow');
    

    DEMO: http://jsfiddle.net/EfpEP/3/

    Alnitak had the great idea of storing the color because the browser can change it to another syntax. But his code is calling document.getElementById each time. Then, taking his idea, I think the best way is:

    function flashtext(ele,col) {
        var style = document.getElementById(ele).style,
            cond=style.color === 'grey';
        (function main(){
            cond=!cond;
            style.color=cond?col:'grey';
            setTimeout(main,cond?1400:700);
        })();
    }
    flashtext('flashingtext','yellow');
    

    DEMO: http://jsfiddle.net/EfpEP/4/

    Edit 2:

    But if you are going to use something like

    flashtext('flashingtext','yellow');
    flashtext('flashingtext2','blue');
    ...
    

    you will end up freezing the browser.

    Instead, you should use

    function FlashText(){
        var arr=[],
            cond=false,
            started=false;
        this.add=function(el,col){
            if(typeof el==='string'){el=document.getElementById(el);}
            arr.push([el.style,col]);
        }
        this.start=function(){
            if(started){return;}
            started=true;
            main();
        }
        function main(){
            cond=!cond;        
            for(var i=0,l=arr.length;i<l;i++){
                arr[i][0].color=cond?arr[i][1]:'grey';
            }
            setTimeout(main,cond?1400:700);
        };
    }
    var flash=new FlashText();
    flash.add('flashingtext','yellow');
    flash.add('flashingtext2','blue');
    flash.start();
    

    You can also call passing an element by reference: flash.add(document.getElementById('flashingtext'),'yellow') (maybe you have a variable which contains an element which has no id).

    But try not to add more elements after flash.start(). If you do that, the element will be black (or default color) until main is called (maybe 1.4 seconds).

    DEMO: http://jsfiddle.net/EfpEP/6/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem to solve from SPOJ -like platform and I can't come
I have a seemingly simple problem whereby I wish to reconcile two lists so
I have problem with UIWebView delay when the load image from url. In my
I have problem SIMILAR to preventing form data reposting, but not quite the same
I have this problem, I have some audio I wish to play... And I
I have this problem: I have a datagridview that reads the data from a
I have a little problem in my little project , I wish that someone
I wish to upload from my Flash Application (AS3) to imageshacks XML API. I
I have the following problem using UNIX Commands. I wish to go through a
I have no problem creating an AJAX call, but each url must at the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.