Results 1 to 4 of 4

Thread: Replace innerHTML of multiple span tags.

Threaded View

  1. #1
    Join Date
    Oct 2008

    Replace innerHTML of multiple span tags.

    The code below works just fine. It replaces the innerHTML of a single span tag named "countDown".

    I've tried to edit the code so it adds the countdown numbers to multiple places (span's) on the page but I can't get anything to work. I tried using 'getElementsByClassName' but I cant figure out what the code should be to use a class instead of an id. I'm assuming that would be the best way or I could use multiple id names like: "countDown1", "countDown2", etc.

    Can someone please tell me what I should change?

    The span's that need to show the countdown are not under the same parent div.

     <script type="text/javascript">
        window.onload = function() {
        startCountDown(120, 1000, myFunction);
        function startCountDown(i, p, f) {
        // store parameters
        var pause = p;
        var fn = f;
        // make reference to div
        var countDownObj = document.getElementById("countDown");
        if (countDownObj == null) {
        // error
        alert("div not found, check your id");
        // bail
        countDownObj.count = function(i) {
        // write out count
        countDownObj.innerHTML = i;
        if (i == 0) {
        // execute function
        // stop
        setTimeout(function() {
        // repeat
        countDownObj.count(i - 1);
        // set it going
        function myFunction() {
        window.setTimeout('window.location="<?php echo $redLink; ?>"; ',2000);
    Last edited by jeffshead; 03-20-2013 at 09:30 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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