Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Aug 2011
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Blinking text in javascript

    I have written a small code in Javascript which does the work of blinking all the content inside any tag with the name 'blink'

    here is the code

    <html>
    <body>
    <p name="blink" style="visibility: visible;">This text blinks using Javascript</p>
    <p name="blink" style="visibility: visible;">This text blinks using Javascript</p>
    <p name="blink" style="visibility: visible;">This text blinks using Javascript</p>
    <p name="blink" style="visibility: visible;">This text blinks using Javascript</p>
    <p name="blink" style="visibility: visible;">This text blinks using Javascript</p>
    <p name="blink" style="visibility: visible;">This text blinks using Javascript</p>
    <p name="blink" style="visibility: visible;">This text blinks using Javascript</p>
    <p name="blink" style="visibility: visible;">This text blinks using Javascript</p>
    <p name="blink" style="visibility: visible;">This text blinks using Javascript</p>
    <p name="blink" style="visibility: visible;">This text blinks using Javascript</p>

    <script type="text/javascript">
    function blinkText()
    {
    var x=document.getElementsByName('blink');
    for(i=0;i<x.length;i++)
    {
    if(x[i].style.visibility=='visible')
    x[i].style.visibility='hidden';
    else
    x[i].style.visibility='visible';
    }
    }
    setTimeout('blinkText()',500);
    </script>
    </body>
    </html>



    I use a Ubuntu system and work on Mozilla 3.6.18
    This hides the text successfully but does not display it again
    What can be wrong here?

    Can anyone please help me
    Last edited by mailkev14; 08-01-2011 at 08:14 AM. Reason: changed the code

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,731
    Thanks
    202
    Thanked 2,508 Times in 2,486 Posts
    javascript blink in innerHTML

    You should note the warning that blink is poor accessibility since it could conceivably trigger a seizure in someone who has photo-sensitive epilepsy - I would advise you not do anything, CSS based or otherwise, that causes text to blink. You could easily find that you have attracted a swarm of expensive lawyers. There is a US standard somewhere about this. (Section 508 Amendment to the Rehabilitation Act of 1973)

    This is all about courage, whether you've got the balls to actually smell what is going on in business. - Alan Sugar BBC1
    Last edited by Philip M; 08-01-2011 at 08:25 AM.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • Users who have thanked Philip M for this post:

    mailkev14 (08-01-2011)

  • #3
    New to the CF scene
    Join Date
    Aug 2011
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by mailkev14 View Post
    I have written a small code in Javascript which does the work of blinking all the content inside any tag with the name 'blink'

    here is the code

    <html>
    <body>
    <p name="blink" style="visibility: visible;">This text blinks using Javascript</p>
    <p name="blink" style="visibility: visible;">This text blinks using Javascript</p>
    <p name="blink" style="visibility: visible;">This text blinks using Javascript</p>
    <p name="blink" style="visibility: visible;">This text blinks using Javascript</p>
    <p name="blink" style="visibility: visible;">This text blinks using Javascript</p>
    <p name="blink" style="visibility: visible;">This text blinks using Javascript</p>
    <p name="blink" style="visibility: visible;">This text blinks using Javascript</p>
    <p name="blink" style="visibility: visible;">This text blinks using Javascript</p>
    <p name="blink" style="visibility: visible;">This text blinks using Javascript</p>
    <p name="blink" style="visibility: visible;">This text blinks using Javascript</p>

    <script type="text/javascript">
    function blinkText()
    {
    var x=document.getElementsByName('blink');
    for(i=0;i<x.length;i++)
    {
    if(x[i].style.visibility=='visible')
    x[i].style.visibility='hidden';
    else
    x[i].style.visibility='visible';
    }
    }
    setTimeout('blinkText()',500);
    </script>
    </body>
    </html>



    I use a Ubuntu system and work on Mozilla 3.6.18
    This hides the text successfully but does not display it again
    What can be wrong here?

    Can anyone please help me
    I got the answer to my quertion itself
    I forgot to add the setTimeout method within the function itself so that it can recursively call itself

  • #4
    New to the CF scene
    Join Date
    Aug 2011
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Philip M View Post
    javascript blink in innerHTML

    You should note the warning that blink is poor accessibility since it could conceivably trigger a seizure in someone who has photo-sensitive epilepsy - I would advise you not do anything, CSS based or otherwise, that causes text to blink. You could easily find that you have attracted a swarm of expensive lawyers. There is a US standard somewhere about this. (Section 508 Amendment to the Rehabilitation Act of 1973)

    This is all about courage, whether you've got the balls to actually smell what is going on in business. - Alan Sugar BBC1
    Thanks for letting me know


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •